xref: /titanic_51/usr/src/lib/libnisdb/db_index_entry_c.x (revision a8ae99647dd4d540346030718e08a083b0fbdf42)
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 %#pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #if RPC_HDR
32 
33 %#ifndef _DB_INDEX_ENTRY_H
34 %#define _DB_INDEX_ENTRY_H
35 
36 %
37 % /* db_index_entry is an entry in the hashtable.  db_index_entries can be
38 %    linked in one of two ways:
39 %    * via the 'next' pointer and form the hash bucket
40 %    * via the 'nextresult' pointer and form a chain of results.
41 %    Each entry contains the key, the hash value of key, and location
42 %    information  'entryp'
43 %    entryp is location information.
44 %    It might be pointer to an in core entry, or an indirect pointer
45 %    identifying the location of an entry somewhere in memory (e.g.
46 %    if there was a table where all complete entries are stored) --- this
47 %    is desirable, for example, for XDR operations on a multi-indexed table;
48 %    or, if used in conjunction with NetISAM, it may be the record number. */
49 %/* *** notes */
50 %/* remember to set next_result to null first if using XDR. */
51 
52 #ifdef USINGC
53 %#include "db_item_c.h"
54 %#include "db_table_c.h"   /* contains definition of entryp */
55 %typedef void *nullptr;
56 #else
57 %#include "db_item.h"
58 %#include "db_table.h"   /* contains definition of entryp */
59 #endif /* USIGNC */
60 #endif /* RPC_HDR */
61 
62 
63 #if RPC_HDR || RPC_XDR
64 #ifdef USINGC
65 struct db_index_entry {
66   unsigned long hashval;
67   item *key;
68   entryp location;
69   db_index_entry* next;
70 #ifdef USINGC
71   nullptr next_result;
72 #else
73   db_index_entry* next_result;
74 #endif
75 };
76 typedef struct db_index_entry * db_index_entry_p;
77 #endif /* USINGC */
78 #endif /* RPC_HDR */
79 
80 #ifndef USINGC
81 #ifdef RPC_HDR
82 %class db_index_entry {
83 %  unsigned long hashval;
84 %  item *key;
85 %  entryp location;
86 %  db_index_entry* next;
87 %  db_index_entry* next_result;
88 % public:
89 %
90 %/* Constructor:  create an entry using given string and location info. */
91 %  db_index_entry( char* name, int nlen, entryp location );
92 %
93 %/* Constructor:  create an entry using the given info.
94 %   A copy of the key is made.  New entry is added to head of list of 'n'. */
95 %  db_index_entry( unsigned long hval, item *, entryp, db_index_entry *n);
96 %
97 %/* Destructor:  deletes key and itself.  Assumes that deletion of
98 %   object at location is done elsewhere (beforehand) */
99 %  ~db_index_entry() {delete key; }
100 %
101 %/* Relocate bucket starting with this entry to new hashtable 'new_tab'. */
102 %  void relocate( db_index_entry**, unsigned long );
103 %
104 %/* Join two lists (entry as identified by its 'location' occurs on both list,
105 %   then it is included in the list returned).
106 %   Returns pointer to resulting list; size of list
107 %   returned in 'newsize'.  List is chained using the 'nextresult' pointer. */
108 %  db_index_entry* join( long size1, long size2, db_index_entry *list2,
109 %		       long * newsize );
110 %
111 %/* Returns pointer to a list of index entries with the same hash value and
112 %   key as those given.  Returns in 'how_many' the number of entries in the
113 %   list returned.  The list is linked by the 'next_result' field of the
114 %   index entries.  These may be changed after the next call to 'lookup'
115 %   or 'join'. */
116 %  db_index_entry* lookup( bool_t, unsigned long, item*, long *);
117 %
118 %/* Return pointer to index entry with same hash value, same key,
119 %   and same record number as those supplied.  Returns NULL if not found. */
120 %  db_index_entry* lookup( bool_t, unsigned long, item*, entryp ); //name entry
121 %
122 %/* Return the next entry in the bucket starting with this entry
123 %   with the same hashvalue, key and location as this entry. */
124 %  db_index_entry* getnext( bool_t, unsigned long, item*, entryp );
125 %
126 %/* Return the next entry in the bucket. */
127 %  db_index_entry* getnextentry() {return next;}
128 %
129 %/* Return the next entry in the 'next_result' chain. */
130 %  db_index_entry* getnextresult() {return next_result;}
131 %
132 %/* Return the location field of this entry. */
133 %  entryp getlocation() {return location;}
134 %
135 %/* Assign the given pointer as the next result after this entry. */
136 %  void addresult( db_index_entry * nr ) { next_result = nr; }
137 %
138 %/* Return the pointer to the key of this entry. */
139 %  item * get_key() {return key;}
140 %
141 %/* Remove entry with the specified hashvalue, key, and record number.
142 %   Returns 'TRUE' if successful, FALSE otherwise.
143 %   If the entry being removed is at the head of the list, then
144 %   the head is updated to reflect the removal. The storage for the index
145 %   entry is freed. The record pointed to by 'recnum' must be removed
146 %   through another means.  All that is updated in this operation is the
147 %   index. */
148 %  bool_t remove( db_index_entry **, bool_t, unsigned long, item *, entryp );
149 %
150 %/* Replace the 'location' field of the index entry with the given one. */
151 %  void replace( entryp ep ) {location = ep;}
152 %
153 %/* Create and add an entry with the given hashvalue, key value, and record
154 %   location, to the bucket pointed to by 'hashvalue'.
155 %   If an entry with the same identical information is found, no addition
156 %   is done.  If an entry with the same hashvalue and key value is found,
157 %   the entry is added after the first entry with this property.  Otherwise,
158 %   the entry is added to the head of the bucket.  This way, entries
159 %   with the same hashvalue and key are not scattered throughout the bucket
160 %   but they occur together. Copy is made of given key. */
161 %  bool_t add( db_index_entry **oldhead, bool_t, unsigned long hval, item *,
162 %	    entryp );
163 %
164 %/* Print this entry to stdout. */
165 %  void print();
166 %
167 %/* Print bucket starting with this entry. */
168 %  void print_all();
169 %
170 %/* Print result list starting with this entry. */
171 %  void print_results();
172 %};
173 %typedef class db_index_entry * db_index_entry_p;
174 #endif /* RPC_HDR */
175 #endif /* USINGC */
176 
177 #if RPC_HDR
178 %#endif /* _DB_INDEX_ENTRY_H */
179 #endif /* RPC_HDR */
180