IDZEBRA  2.2.7
orddict.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <assert.h>
24 #include <yaz/wrbuf.h>
25 #include "index.h"
26 
27 WRBUF zebra_mk_ord_str(int ord, const char *str)
28 {
29  char pref[20];
30  WRBUF w = wrbuf_alloc();
31  int len;
32 
33  assert(ord >= 0);
34 
35  len = key_SU_encode(ord, pref);
36 
37  wrbuf_write(w, pref, len);
38  wrbuf_puts(w, str);
39  return w;
40 }
41 
42 char *dict_lookup_ord(Dict d, int ord, const char *str)
43 {
44  WRBUF w = zebra_mk_ord_str(ord, str);
45  char *rinfo = dict_lookup(d, wrbuf_cstr(w));
46  wrbuf_destroy(w);
47  return rinfo;
48 }
49 
50 int dict_insert_ord(Dict d, int ord, const char *p,
51  int userlen, void *userinfo)
52 {
53  WRBUF w = zebra_mk_ord_str(ord, p);
54  int r = dict_insert(d, wrbuf_cstr(w), userlen, userinfo);
55  wrbuf_destroy(w);
56  return r;
57 }
58 
59 int dict_delete_ord(Dict d, int ord, const char *p)
60 {
61  WRBUF w = zebra_mk_ord_str(ord, p);
62  int r = dict_delete(d, wrbuf_cstr(w));
63  wrbuf_destroy(w);
64  return r;
65 }
66 
67 int dict_delete_subtree_ord(Dict d, int ord, void *client,
68  int (*f)(const char *info, void *client))
69 {
70  WRBUF w = zebra_mk_ord_str(ord, "");
71  int r = dict_delete_subtree(d, wrbuf_cstr(w), client, f);
72  wrbuf_destroy(w);
73  return r;
74 }
75 /*
76  * Local variables:
77  * c-basic-offset: 4
78  * c-file-style: "Stroustrup"
79  * indent-tabs-mode: nil
80  * End:
81  * vim: shiftwidth=4 tabstop=8 expandtab
82  */
83 
char * dict_lookup(Dict dict, const char *p)
lookup item in dictionary
Definition: lookup.c:100
int dict_delete(Dict dict, const char *p)
deletes item from dictionary
Definition: delete.c:260
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
Definition: delete.c:266
int dict_insert(Dict dict, const char *p, int userlen, void *userinfo)
insert item into dictionary
Definition: insert.c:439
int key_SU_encode(int ch, char *out)
Definition: su_codec.c:31
int dict_delete_subtree_ord(Dict d, int ord, void *client, int(*f)(const char *info, void *client))
Definition: orddict.c:67
char * dict_lookup_ord(Dict d, int ord, const char *str)
Definition: orddict.c:42
int dict_insert_ord(Dict d, int ord, const char *p, int userlen, void *userinfo)
Definition: orddict.c:50
WRBUF zebra_mk_ord_str(int ord, const char *str)
Definition: orddict.c:27
int dict_delete_ord(Dict d, int ord, const char *p)
Definition: orddict.c:59