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
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.
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]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 %#pragma ident "%Z%%M% %I% %E% SMI"
33 %#ifndef _DB_INDEX_ENTRY_H
34 %#define _DB_INDEX_ENTRY_H
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. */
50 %/* remember to set next_result to null first if using XDR. */
53 %#include "db_item_c.h"
54 %#include "db_table_c.h" /* contains definition of entryp */
55 %typedef void *nullptr;
58 %#include "db_table.h" /* contains definition of entryp */
63 #if RPC_HDR || RPC_XDR
65 struct db_index_entry {
66 unsigned long hashval;
73 db_index_entry* next_result;
76 typedef struct db_index_entry * db_index_entry_p;
82 %class db_index_entry {
83 % unsigned long hashval;
86 % db_index_entry* next;
87 % db_index_entry* next_result;
90 %/* Constructor: create an entry using given string and location info. */
91 % db_index_entry( char* name, int nlen, entryp location );
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);
97 %/* Destructor: deletes key and itself. Assumes that deletion of
98 % object at location is done elsewhere (beforehand) */
99 % ~db_index_entry() {delete key; }
101 %/* Relocate bucket starting with this entry to new hashtable 'new_tab'. */
102 % void relocate( db_index_entry**, unsigned long );
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,
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'
116 % db_index_entry* lookup( bool_t, unsigned long, item*, long *);
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
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 );
126 %/* Return the next entry in the bucket. */
127 % db_index_entry* getnextentry() {return next;}
129 %/* Return the next entry in the 'next_result' chain. */
130 % db_index_entry* getnextresult() {return next_result;}
132 %/* Return the location field of this entry. */
133 % entryp getlocation() {return location;}
135 %/* Assign the given pointer as the next result after this entry. */
136 % void addresult( db_index_entry * nr ) { next_result = nr; }
138 %/* Return the pointer to the key of this entry. */
139 % item * get_key() {return key;}
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
148 % bool_t remove( db_index_entry **, bool_t, unsigned long, item *, entryp );
150 %/* Replace the 'location' field of the index entry with the given one. */
151 % void replace( entryp ep ) {location = ep;}
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 *,
164 %/* Print this entry to stdout. */
167 %/* Print bucket starting with this entry. */
170 %/* Print result list starting with this entry. */
171 % void print_results();
173 %typedef class db_index_entry * db_index_entry_p;
178 %#endif /* _DB_INDEX_ENTRY_H */