2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 2002-07-12 18:12:22 heikki
8 * Isam-D now stores small entries directly in the dictionary.
9 * Needs more tuning and cleaning...
11 * Revision 1.2 2002/04/05 08:46:26 adam
12 * Zebra with full functionality
14 * Revision 1.1 2001/01/16 19:17:18 heikki
26 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
27 static RSFD r_open (RSET ct, int flag);
28 static void r_close (RSFD rfd);
29 static void r_delete (RSET ct);
30 static void r_rewind (RSFD rfd);
31 static int r_count (RSET ct);
32 static int r_read (RSFD rfd, void *buf, int *term_index);
33 static int r_write (RSFD rfd, const void *buf);
35 static const struct rset_control control =
48 const struct rset_control *rset_kind_isamd = &control;
52 struct rset_pp_info *next;
53 struct rset_isamd_info *info;
56 struct rset_isamd_info {
59 char dictentry[ISAMD_MAX_DICT_LEN];
61 struct rset_pp_info *ispt_list;
64 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
66 rset_isamd_parms *pt = (rset_isamd_parms *) parms;
67 struct rset_isamd_info *info;
69 ct->flags |= RSET_FLAG_VOLATILE;
70 info = (struct rset_isamd_info *) xmalloc (sizeof(*info));
72 /*info->pos = pt->pos;*/
73 info->dictlen = pt->dictlen;
74 memcpy(info->dictentry, pt->dictentry, pt->dictlen);
75 info->ispt_list = NULL;
76 ct->no_rset_terms = 1;
77 ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
78 ct->rset_terms[0] = pt->rset_term;
82 RSFD r_open (RSET ct, int flag)
84 struct rset_isamd_info *info = (struct rset_isamd_info *) ct->buf;
85 struct rset_pp_info *ptinfo;
87 logf (LOG_DEBUG, "risamd_open");
88 if (flag & RSETF_WRITE)
90 logf (LOG_FATAL, "ISAMD set type is read-only");
93 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
94 ptinfo->next = info->ispt_list;
95 info->ispt_list = ptinfo;
96 ptinfo->pt = isamd_pp_open (info->is, info->dictentry, info->dictlen);
98 if (ct->rset_terms[0]->nn < 0)
99 ct->rset_terms[0]->nn = isamd_pp_num (ptinfo->pt);
103 static void r_close (RSFD rfd)
105 struct rset_isamd_info *info = ((struct rset_pp_info*) rfd)->info;
106 struct rset_pp_info **ptinfop;
108 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
111 isamd_pp_close ((*ptinfop)->pt);
112 *ptinfop = (*ptinfop)->next;
116 logf (LOG_FATAL, "r_close but no rfd match!");
120 static void r_delete (RSET ct)
122 struct rset_isamd_info *info = (struct rset_isamd_info *) ct->buf;
124 logf (LOG_DEBUG, "rsisamd_delete");
125 assert (info->ispt_list == NULL);
126 rset_term_destroy (ct->rset_terms[0]);
127 xfree (ct->rset_terms);
131 static void r_rewind (RSFD rfd)
133 logf (LOG_DEBUG, "rsisamd_rewind");
137 static int r_count (RSET ct)
142 static int r_read (RSFD rfd, void *buf, int *term_index)
145 return isamd_pp_read( ((struct rset_pp_info*) rfd)->pt, buf);
148 static int r_write (RSFD rfd, const void *buf)
150 logf (LOG_FATAL, "ISAMD set type is read-only");