X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Forddict.c;fp=index%2Forddict.c;h=e93d04f1f11c3936fdbee76da0939567c81569f0;hb=1d09966e51904c44ed82eaa920ffc9fbcc087541;hp=ed4a05fc40dd973dc0b2d40d7b1dc075456512f6;hpb=1ef7d46cdc719bc71b84ea81a1e7b467f9669fba;p=idzebra-moved-to-github.git diff --git a/index/orddict.c b/index/orddict.c index ed4a05f..e93d04f 100644 --- a/index/orddict.c +++ b/index/orddict.c @@ -1,35 +1,74 @@ +/* $Id: orddict.c,v 1.2 2006-02-09 08:31:02 adam Exp $ + Copyright (C) 1995-2005 + Index Data ApS -#include +This file is part of the Zebra server. -#include "orddict.h" +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. -struct zebra_ord_dict { - char *str; - size_t str_sz; - Dict dict; -}; +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. -Zebra_ord_dict zebra_ord_dict_open(Dict dict) +You should have received a copy of the GNU General Public License +along with Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + +#include +#include +#include "index.h" + +WRBUF zebra_mk_ord_str(int ord, const char *str) +{ + char pref[20]; + WRBUF w = wrbuf_alloc(); + int len; + + assert(ord >= 0); + + len = key_SU_encode(ord, pref); + + wrbuf_write(w, pref, len); + wrbuf_puts(w, str); + return w; +} + +char *dict_lookup_ord(Dict d, int ord, const char *str) { - Zebra_ord_dict zod = xmalloc(sizeof(*zod)); - zod->str_sz = 50; - zod->str = xmalloc(zod->str_sz); - zod->dict = dict; - return zod; + WRBUF w = zebra_mk_ord_str(ord, str); + char *rinfo = dict_lookup(d, wrbuf_buf(w)); + wrbuf_free(w, 1); + return rinfo; } -void zebra_ord_dict_close(Zebra_ord_dict zod) +int dict_insert_ord(Dict d, int ord, const char *p, + int userlen, void *userinfo) { - if (!zod) - return; - dict_close(zod->dict); - xfree(zod->str); - xfree(zod); + WRBUF w = zebra_mk_ord_str(ord, p); + int r = dict_insert(d, wrbuf_buf(w), userlen, userinfo); + wrbuf_free(w, 1); + return r; } -char *zebra_ord_dict_lookup (Zebra_ord_dict zod, int ord, - const char *p) +int dict_delete_ord(Dict d, int ord, const char *p) { - return dict_lookup(zod->dict, p); + WRBUF w = zebra_mk_ord_str(ord, p); + int r = dict_delete(d, wrbuf_buf(w)); + wrbuf_free(w, 1); + return r; } +int dict_delete_subtree_ord(Dict d, int ord, void *client, + int (*f)(const char *info, void *client)) +{ + WRBUF w = zebra_mk_ord_str(ord, ""); + int r = dict_delete_subtree(d, wrbuf_buf(w), client, f); + wrbuf_free(w, 1); + return r; +}