IDZEBRA  2.1.3
Typedefs | Functions
dict.h File Reference

Zebra dictionary. More...

#include <yaz/yconfig.h>
#include <idzebra/bfile.h>

Go to the source code of this file.

Typedefs

typedef struct Dict_structDict
 Dictionary handle. More...
 

Functions

Dict dict_open (BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size)
 open dictionary More...
 
int dict_close (Dict dict)
 closes dictionary More...
 
int dict_insert (Dict dict, const char *p, int userlen, void *userinfo)
 insert item into dictionary More...
 
int dict_delete (Dict dict, const char *p)
 deletes item from dictionary More...
 
char * dict_lookup (Dict dict, const char *p)
 lookup item in dictionary More...
 
int dict_delete_subtree (Dict dict, const char *p, void *client, int(*f)(const char *info, void *client))
 delete items with a given prefix from dictionary More...
 
int dict_lookup_ec (Dict dict, char *p, int range, int(*f)(char *name))
 lookup item(s) in dictionary with error correction More...
 
int dict_lookup_grep (Dict dict, const char *p, int range, void *client, int *max_pos, int init_pos, int(*f)(char *name, const char *info, void *client))
 regular expression search with error correction More...
 
int dict_scan (Dict dict, char *str, int *before, int *after, void *client, int(*f)(char *name, const char *info, int pos, void *client))
 dictionary scan More...
 
void dict_grep_cmap (Dict dict, void *vp, const char **(*cmap)(void *vp, const char **from, int len))
 install character mapping handler for dict_lookup_grep More...
 
int dict_copy_compact (BFiles bfs, const char *from, const char *to)
 copies one dictionary to another More...
 
void dict_clean (Dict dict)
 reset Dictionary (makes it empty) More...
 
zint dict_get_no_lookup (Dict dict)
 get number of lookup operations, since dict_open More...
 
zint dict_get_no_insert (Dict dict)
 get number of insert operations, since dict_open More...
 
zint dict_get_no_split (Dict dict)
 get number of page split operations, since dict_open More...
 

Detailed Description

Zebra dictionary.

The dictionary is a hash that maps a string to a value. The value is opaque and is defined as a sequence of bytes with a length in the range 0 to 255.

Definition in file dict.h.

Typedef Documentation

Dictionary handle.

Most dictionary functions operatate on a Dict type (object).

Definition at line 41 of file dict.h.

Function Documentation

void dict_clean ( Dict  dict)

reset Dictionary (makes it empty)

Parameters
dictdictionary handle

Definition at line 31 of file open.c.

References Dict_head::compact_flag, Dict_struct::dbf, dict_bf_newp(), DICT_MAGIC, Dict_head::freelist, Dict_struct::head, Dict_head::last, Dict_head::magic_str, Dict_head::page_size, Dict_head::root, and Dict_struct::rw.

Referenced by dict_open(), and zebra_remove_file_match().

int dict_close ( Dict  dict)

closes dictionary

Parameters
dicthandle
Return values
0OK
-1failure

Definition at line 32 of file close.c.

References Dict_struct::dbf, dict_bf_close(), dict_bf_readp(), dict_bf_touch(), Dict_struct::head, and Dict_struct::rw.

Referenced by dict_copy_compact(), main(), repositoryShow(), zebra_register_close(), zebra_remove_file_match(), and zebra_update_file_match().

int dict_copy_compact ( BFiles  bfs,
const char *  from,
const char *  to 
)

copies one dictionary to another

Parameters
bfsblock file handle
fromsource dictionary file
todestination dictionary file

Definition at line 90 of file dcompact.c.

References Dict_struct::dbf, DICT_backptr, dict_bf_newp(), dict_bf_readp(), DICT_bsize, dict_close(), dict_copy_page(), DICT_nodir, dict_open(), DICT_size, DICT_type, Dict_struct::head, Dict_head::last, Dict_head::page_size, and Dict_head::root.

Referenced by inv_compact().

int dict_delete ( Dict  dict,
const char *  p 
)

deletes item from dictionary

Parameters
dictdictionary handle
pstring-z with lookup string
Return values
0p not found
1p found and deleted
-1error

Definition at line 260 of file delete.c.

References dict_del_string(), Dict_struct::head, and Dict_head::root.

Referenced by dict_delete_ord(), dirs_del(), dirs_rmdir(), heap_inpb(), heap_inpc(), and main().

int dict_delete_subtree ( Dict  dict,
const char *  p,
void *  client,
int(*)(const char *info, void *client)  f 
)

delete items with a given prefix from dictionary

Parameters
dictdictionary handle
pstring-z with prefix
clientclient data to be supplied to function f
ffunction which gets called for each item in tree
Return values
0OK (0 or more entries deleted)
1OK (1 or more entries delete)
-1ERROR

Function f is called for each item to be deleted.

Definition at line 266 of file delete.c.

References dict_del_string(), Dict_struct::head, and Dict_head::root.

Referenced by delete_SU_handle(), dict_delete_subtree_ord(), and main().

zint dict_get_no_insert ( Dict  dict)

get number of insert operations, since dict_open

Parameters
dictdictionary handle
Returns
number of operatons

Definition at line 128 of file open.c.

References Dict_struct::no_insert.

zint dict_get_no_lookup ( Dict  dict)

get number of lookup operations, since dict_open

Parameters
dictdictionary handle
Returns
number of operatons

Definition at line 123 of file open.c.

References Dict_struct::no_lookup.

zint dict_get_no_split ( Dict  dict)

get number of page split operations, since dict_open

Parameters
dictdictionary handle
Returns
number of operatons

Definition at line 133 of file open.c.

References Dict_struct::no_split.

Referenced by index_block_flush().

void dict_grep_cmap ( Dict  dict,
void *  vp,
const char **(*)(void *vp, const char **from, int len)  cmap 
)

install character mapping handler for dict_lookup_grep

Parameters
dictdictionary handle
vpclient data to be passed to cmap function handler
cmapfunction be called for each character

This function must be called prior to using dict_grep_lookup. If vp is NULL, no character mapping takes place for dict_lookup_grep.

Definition at line 445 of file lookgrep.c.

References Dict_struct::grep_cmap, and Dict_struct::grep_cmap_data.

Referenced by rpn_char_map_prepare(), and rpn_search_xpath().

int dict_insert ( Dict  dict,
const char *  p,
int  userlen,
void *  userinfo 
)

insert item into dictionary

Parameters
dictdictionary handle
pstring-z with lookup string
userlenlength of user data (associated with p)
userinfouserdata (of size userlen)
Return values
0p is new and inserted OK
1p is updated (already exists) and userinfo is modified
2p already exists and userinfo is unmodified (same as before)
-1error

Definition at line 438 of file insert.c.

References dict_ins(), Dict_struct::head, new_page(), Dict_struct::no_insert, Dict_head::root, and Dict_struct::rw.

Referenced by dict_insert_ord(), dirs_add(), dirs_mkdir(), heap_inpb(), heap_inpc(), heap_inps(), index_block_flush(), main(), and tst().

char* dict_lookup ( Dict  dict,
const char *  p 
)

lookup item in dictionary

Parameters
dictdictionary handle
pstring-z with lookup string
Return values
NULLnot found
valuewhere value[0]=userlen, value[1..userlen] is userinfo data

Definition at line 100 of file lookup.c.

References dict_look(), Dict_struct::head, Dict_struct::no_lookup, and Dict_head::root.

Referenced by dict_lookup_ord(), dirs_fopen(), freq_term(), heap_inpb(), heap_inpc(), heap_inps(), index_block_flush(), main(), search_group(), search_position(), zebra_recid_to_sysno(), and zebra_record_check().

int dict_lookup_ec ( Dict  dict,
char *  p,
int  range,
int(*)(char *name)  f 
)

lookup item(s) in dictionary with error correction

Parameters
dictdictionary handle
pstring-z with lookup string
rangenumber of allowed errors(extra/substituted/missing char)
ffunction be called for each match (NULL for no call of f)
Return values
0OK
-1error

Function f is called for each item matched.

Definition at line 149 of file lookupec.c.

References dict_strlen(), Dict_struct::head, lookup_ec(), prepare_match(), and Dict_head::root.

int dict_lookup_grep ( Dict  dict,
const char *  p,
int  range,
void *  client,
int *  max_pos,
int  init_pos,
int(*)(char *name, const char *info, void *client)  f 
)

regular expression search with error correction

Parameters
dictdictionary handle
pregular expression string-z
rangenumber of allowed errors(extra/substituted/missing char)
clientclient data pointer to be passed to match function f
max_poson return holds maximum number of chars that match (prefix)
init_posnumber of leading non-error corrected chars.
ffunction be called for each match
Return values
0Operation complete. Function f returned zero value always
>0Operation incomplete. Function f returned a non-zero value
-1error (such as bad regular expression)

The function f is called for each match. If function f returns non-zero value the grep operation is stopped and the returned non-zero value is also returned by dict_lookup_ec.

Definition at line 374 of file lookgrep.c.

References debug_dfa_followpos, debug_dfa_tran, debug_dfa_trav, dfa_anyset_includes_nl(), dfa_delete(), dfa_init(), dfa_mkstate(), dfa_parse(), dfa_set_cmap(), dfa_verbose, MatchContext::fact, get_bit(), grep(), Dict_struct::grep_cmap, Dict_struct::grep_cmap_data, Dict_struct::head, MAX_LENGTH, mk_MatchContext(), MatchContext::n, DFA::no_states, MatchContext::range, rm_MatchContext(), Dict_head::root, set_bit(), DFA::states, DFA_tran::to, DFA_state::tran_no, and DFA_state::trans.

Referenced by main(), numeric_relation(), string_term(), and xpath_trunc().

Dict dict_open ( BFiles  bfs,
const char *  name,
int  cache,
int  rw,
int  compact_flag,
int  page_size 
)

open dictionary

Parameters
bfsblock file storage
namename of dictionary file
cachenumber of pages to cache
rw0=read-only, 1=read&write
compact_flag1=write with compact, 0=normal paged operation
page_sizepage size of disc block
Returns
dictionary handle

Definition at line 50 of file open.c.

References Dict_head::compact_flag, Dict_struct::dbf, dict, dict_bf_close(), dict_bf_compact(), dict_bf_open(), dict_bf_readp(), dict_clean(), DICT_DEFAULT_PAGESIZE, DICT_MAGIC, Dict_struct::grep_cmap, Dict_struct::head, Dict_head::magic_str, Dict_struct::no_insert, Dict_struct::no_lookup, Dict_struct::no_split, Dict_head::page_size, and Dict_struct::rw.

Referenced by dict_copy_compact(), dict_open_res(), and main().

int dict_scan ( Dict  dict,
char *  str,
int *  before,
int *  after,
void *  client,
int(*)(char *name, const char *info, int pos, void *client)  f 
)

dictionary scan

Parameters
dictdictionary handle
strstart pint term (string-z)
beforenumber of terms to be visited preceding str
afternumber of terms to be visited following str
clientclient data pointer to be passed to match function f
ffunction be called for each matching term
Return values
0Successful
-1error

If the callback function f returns 0 the scan operation visits all terms in range (before to after); if the function returns non-zero the scan operation is cancelled.

Definition at line 242 of file scan.c.

References dict_scan_r(), Dict_struct::head, and Dict_head::root.

Referenced by dirs_open(), dirs_read(), do_scan(), main(), rpn_scan_norm(), and zebra_register_statistics().