xref: /illumos-gate/usr/src/lib/libnisdb/db_index_entry_c.x (revision 8361acf58a302751348aac091ab09484f3ecfb8c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	db_index_entry_c.x
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #if RPC_HDR
30 
31 %#ifndef _DB_INDEX_ENTRY_H
32 %#define _DB_INDEX_ENTRY_H
33 
34 %
35 % /* db_index_entry is an entry in the hashtable.  db_index_entries can be
36 %    linked in one of two ways:
37 %    * via the 'next' pointer and form the hash bucket
38 %    * via the 'nextresult' pointer and form a chain of results.
39 %    Each entry contains the key, the hash value of key, and location
40 %    information  'entryp'
41 %    entryp is location information.
42 %    It might be pointer to an in core entry, or an indirect pointer
43 %    identifying the location of an entry somewhere in memory (e.g.
44 %    if there was a table where all complete entries are stored) --- this
45 %    is desirable, for example, for XDR operations on a multi-indexed table;
46 %    or, if used in conjunction with NetISAM, it may be the record number. */
47 %/* *** notes */
48 %/* remember to set next_result to null first if using XDR. */
49 
50 #ifdef USINGC
51 %#include "db_item_c.h"
52 %#include "db_table_c.h"   /* contains definition of entryp */
53 %typedef void *nullptr;
54 #else
55 %#include "db_item.h"
56 %#include "db_table.h"   /* contains definition of entryp */
57 #endif /* USIGNC */
58 #endif /* RPC_HDR */
59 
60 
61 #if RPC_HDR || RPC_XDR
62 #ifdef USINGC
63 struct db_index_entry {
64   unsigned long hashval;
65   item *key;
66   entryp location;
67   db_index_entry* next;
68 #ifdef USINGC
69   nullptr next_result;
70 #else
71   db_index_entry* next_result;
72 #endif
73 };
74 typedef struct db_index_entry * db_index_entry_p;
75 #endif /* USINGC */
76 #endif /* RPC_HDR */
77 
78 #ifndef USINGC
79 #ifdef RPC_HDR
80 %class db_index_entry {
81 %  unsigned long hashval;
82 %  item *key;
83 %  entryp location;
84 %  db_index_entry* next;
85 %  db_index_entry* next_result;
86 % public:
87 %
88 %/* Constructor:  create an entry using given string and location info. */
89 %  db_index_entry( char* name, int nlen, entryp location );
90 %
91 %/* Constructor:  create an entry using the given info.
92 %   A copy of the key is made.  New entry is added to head of list of 'n'. */
93 %  db_index_entry( unsigned long hval, item *, entryp, db_index_entry *n);
94 %
95 %/* Destructor:  deletes key and itself.  Assumes that deletion of
96 %   object at location is done elsewhere (beforehand) */
97 %  ~db_index_entry() {delete key; }
98 %
99 %/* Relocate bucket starting with this entry to new hashtable 'new_tab'. */
100 %  void relocate( db_index_entry**, unsigned long );
101 %
102 %/* Join two lists (entry as identified by its 'location' occurs on both list,
103 %   then it is included in the list returned).
104 %   Returns pointer to resulting list; size of list
105 %   returned in 'newsize'.  List is chained using the 'nextresult' pointer. */
106 %  db_index_entry* join( long size1, long size2, db_index_entry *list2,
107 %		       long * newsize );
108 %
109 %/* Returns pointer to a list of index entries with the same hash value and
110 %   key as those given.  Returns in 'how_many' the number of entries in the
111 %   list returned.  The list is linked by the 'next_result' field of the
112 %   index entries.  These may be changed after the next call to 'lookup'
113 %   or 'join'. */
114 %  db_index_entry* lookup( bool_t, unsigned long, item*, long *);
115 %
116 %/* Return pointer to index entry with same hash value, same key,
117 %   and same record number as those supplied.  Returns NULL if not found. */
118 %  db_index_entry* lookup( bool_t, unsigned long, item*, entryp ); //name entry
119 %
120 %/* Return the next entry in the bucket starting with this entry
121 %   with the same hashvalue, key and location as this entry. */
122 %  db_index_entry* getnext( bool_t, unsigned long, item*, entryp );
123 %
124 %/* Return the next entry in the bucket. */
125 %  db_index_entry* getnextentry() {return next;}
126 %
127 %/* Return the next entry in the 'next_result' chain. */
128 %  db_index_entry* getnextresult() {return next_result;}
129 %
130 %/* Return the location field of this entry. */
131 %  entryp getlocation() {return location;}
132 %
133 %/* Assign the given pointer as the next result after this entry. */
134 %  void addresult( db_index_entry * nr ) { next_result = nr; }
135 %
136 %/* Return the pointer to the key of this entry. */
137 %  item * get_key() {return key;}
138 %
139 %/* Remove entry with the specified hashvalue, key, and record number.
140 %   Returns 'TRUE' if successful, FALSE otherwise.
141 %   If the entry being removed is at the head of the list, then
142 %   the head is updated to reflect the removal. The storage for the index
143 %   entry is freed. The record pointed to by 'recnum' must be removed
144 %   through another means.  All that is updated in this operation is the
145 %   index. */
146 %  bool_t remove( db_index_entry **, bool_t, unsigned long, item *, entryp );
147 %
148 %/* Replace the 'location' field of the index entry with the given one. */
149 %  void replace( entryp ep ) {location = ep;}
150 %
151 %/* Create and add an entry with the given hashvalue, key value, and record
152 %   location, to the bucket pointed to by 'hashvalue'.
153 %   If an entry with the same identical information is found, no addition
154 %   is done.  If an entry with the same hashvalue and key value is found,
155 %   the entry is added after the first entry with this property.  Otherwise,
156 %   the entry is added to the head of the bucket.  This way, entries
157 %   with the same hashvalue and key are not scattered throughout the bucket
158 %   but they occur together. Copy is made of given key. */
159 %  bool_t add( db_index_entry **oldhead, bool_t, unsigned long hval, item *,
160 %	    entryp );
161 %
162 %/* Print this entry to stdout. */
163 %  void print();
164 %
165 %/* Print bucket starting with this entry. */
166 %  void print_all();
167 %
168 %/* Print result list starting with this entry. */
169 %  void print_results();
170 %};
171 %typedef class db_index_entry * db_index_entry_p;
172 #endif /* RPC_HDR */
173 #endif /* USINGC */
174 
175 #if RPC_HDR
176 %#endif /* _DB_INDEX_ENTRY_H */
177 #endif /* RPC_HDR */
178