17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	db_index_entry_c.x
247c478bd9Sstevel@tonic-gate  *
25*a506a34cSth160488  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*a506a34cSth160488  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #if RPC_HDR
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate %#ifndef _DB_INDEX_ENTRY_H
327c478bd9Sstevel@tonic-gate %#define _DB_INDEX_ENTRY_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate %
357c478bd9Sstevel@tonic-gate % /* db_index_entry is an entry in the hashtable.  db_index_entries can be
367c478bd9Sstevel@tonic-gate %    linked in one of two ways:
377c478bd9Sstevel@tonic-gate %    * via the 'next' pointer and form the hash bucket
387c478bd9Sstevel@tonic-gate %    * via the 'nextresult' pointer and form a chain of results.
397c478bd9Sstevel@tonic-gate %    Each entry contains the key, the hash value of key, and location
407c478bd9Sstevel@tonic-gate %    information  'entryp'
417c478bd9Sstevel@tonic-gate %    entryp is location information.
427c478bd9Sstevel@tonic-gate %    It might be pointer to an in core entry, or an indirect pointer
437c478bd9Sstevel@tonic-gate %    identifying the location of an entry somewhere in memory (e.g.
447c478bd9Sstevel@tonic-gate %    if there was a table where all complete entries are stored) --- this
457c478bd9Sstevel@tonic-gate %    is desirable, for example, for XDR operations on a multi-indexed table;
467c478bd9Sstevel@tonic-gate %    or, if used in conjunction with NetISAM, it may be the record number. */
477c478bd9Sstevel@tonic-gate %/* *** notes */
487c478bd9Sstevel@tonic-gate %/* remember to set next_result to null first if using XDR. */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifdef USINGC
517c478bd9Sstevel@tonic-gate %#include "db_item_c.h"
527c478bd9Sstevel@tonic-gate %#include "db_table_c.h"   /* contains definition of entryp */
537c478bd9Sstevel@tonic-gate %typedef void *nullptr;
547c478bd9Sstevel@tonic-gate #else
557c478bd9Sstevel@tonic-gate %#include "db_item.h"
567c478bd9Sstevel@tonic-gate %#include "db_table.h"   /* contains definition of entryp */
57*a506a34cSth160488 #endif /* USIGNC */
58*a506a34cSth160488 #endif /* RPC_HDR */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
627c478bd9Sstevel@tonic-gate #ifdef USINGC
637c478bd9Sstevel@tonic-gate struct db_index_entry {
647c478bd9Sstevel@tonic-gate   unsigned long hashval;
657c478bd9Sstevel@tonic-gate   item *key;
667c478bd9Sstevel@tonic-gate   entryp location;
677c478bd9Sstevel@tonic-gate   db_index_entry* next;
687c478bd9Sstevel@tonic-gate #ifdef USINGC
697c478bd9Sstevel@tonic-gate   nullptr next_result;
707c478bd9Sstevel@tonic-gate #else
717c478bd9Sstevel@tonic-gate   db_index_entry* next_result;
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate typedef struct db_index_entry * db_index_entry_p;
75*a506a34cSth160488 #endif /* USINGC */
76*a506a34cSth160488 #endif /* RPC_HDR */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #ifndef USINGC
797c478bd9Sstevel@tonic-gate #ifdef RPC_HDR
807c478bd9Sstevel@tonic-gate %class db_index_entry {
817c478bd9Sstevel@tonic-gate %  unsigned long hashval;
827c478bd9Sstevel@tonic-gate %  item *key;
837c478bd9Sstevel@tonic-gate %  entryp location;
847c478bd9Sstevel@tonic-gate %  db_index_entry* next;
857c478bd9Sstevel@tonic-gate %  db_index_entry* next_result;
867c478bd9Sstevel@tonic-gate % public:
877c478bd9Sstevel@tonic-gate %
887c478bd9Sstevel@tonic-gate %/* Constructor:  create an entry using given string and location info. */
897c478bd9Sstevel@tonic-gate %  db_index_entry( char* name, int nlen, entryp location );
907c478bd9Sstevel@tonic-gate %
917c478bd9Sstevel@tonic-gate %/* Constructor:  create an entry using the given info.
927c478bd9Sstevel@tonic-gate %   A copy of the key is made.  New entry is added to head of list of 'n'. */
937c478bd9Sstevel@tonic-gate %  db_index_entry( unsigned long hval, item *, entryp, db_index_entry *n);
947c478bd9Sstevel@tonic-gate %
957c478bd9Sstevel@tonic-gate %/* Destructor:  deletes key and itself.  Assumes that deletion of
967c478bd9Sstevel@tonic-gate %   object at location is done elsewhere (beforehand) */
977c478bd9Sstevel@tonic-gate %  ~db_index_entry() {delete key; }
987c478bd9Sstevel@tonic-gate %
997c478bd9Sstevel@tonic-gate %/* Relocate bucket starting with this entry to new hashtable 'new_tab'. */
1007c478bd9Sstevel@tonic-gate %  void relocate( db_index_entry**, unsigned long );
1017c478bd9Sstevel@tonic-gate %
1027c478bd9Sstevel@tonic-gate %/* Join two lists (entry as identified by its 'location' occurs on both list,
1037c478bd9Sstevel@tonic-gate %   then it is included in the list returned).
1047c478bd9Sstevel@tonic-gate %   Returns pointer to resulting list; size of list
1057c478bd9Sstevel@tonic-gate %   returned in 'newsize'.  List is chained using the 'nextresult' pointer. */
1067c478bd9Sstevel@tonic-gate %  db_index_entry* join( long size1, long size2, db_index_entry *list2,
1077c478bd9Sstevel@tonic-gate %		       long * newsize );
1087c478bd9Sstevel@tonic-gate %
1097c478bd9Sstevel@tonic-gate %/* Returns pointer to a list of index entries with the same hash value and
1107c478bd9Sstevel@tonic-gate %   key as those given.  Returns in 'how_many' the number of entries in the
1117c478bd9Sstevel@tonic-gate %   list returned.  The list is linked by the 'next_result' field of the
1127c478bd9Sstevel@tonic-gate %   index entries.  These may be changed after the next call to 'lookup'
1137c478bd9Sstevel@tonic-gate %   or 'join'. */
1147c478bd9Sstevel@tonic-gate %  db_index_entry* lookup( bool_t, unsigned long, item*, long *);
1157c478bd9Sstevel@tonic-gate %
1167c478bd9Sstevel@tonic-gate %/* Return pointer to index entry with same hash value, same key,
1177c478bd9Sstevel@tonic-gate %   and same record number as those supplied.  Returns NULL if not found. */
1187c478bd9Sstevel@tonic-gate %  db_index_entry* lookup( bool_t, unsigned long, item*, entryp ); //name entry
1197c478bd9Sstevel@tonic-gate %
1207c478bd9Sstevel@tonic-gate %/* Return the next entry in the bucket starting with this entry
1217c478bd9Sstevel@tonic-gate %   with the same hashvalue, key and location as this entry. */
1227c478bd9Sstevel@tonic-gate %  db_index_entry* getnext( bool_t, unsigned long, item*, entryp );
1237c478bd9Sstevel@tonic-gate %
1247c478bd9Sstevel@tonic-gate %/* Return the next entry in the bucket. */
1257c478bd9Sstevel@tonic-gate %  db_index_entry* getnextentry() {return next;}
1267c478bd9Sstevel@tonic-gate %
1277c478bd9Sstevel@tonic-gate %/* Return the next entry in the 'next_result' chain. */
1287c478bd9Sstevel@tonic-gate %  db_index_entry* getnextresult() {return next_result;}
1297c478bd9Sstevel@tonic-gate %
1307c478bd9Sstevel@tonic-gate %/* Return the location field of this entry. */
1317c478bd9Sstevel@tonic-gate %  entryp getlocation() {return location;}
1327c478bd9Sstevel@tonic-gate %
1337c478bd9Sstevel@tonic-gate %/* Assign the given pointer as the next result after this entry. */
1347c478bd9Sstevel@tonic-gate %  void addresult( db_index_entry * nr ) { next_result = nr; }
1357c478bd9Sstevel@tonic-gate %
1367c478bd9Sstevel@tonic-gate %/* Return the pointer to the key of this entry. */
1377c478bd9Sstevel@tonic-gate %  item * get_key() {return key;}
1387c478bd9Sstevel@tonic-gate %
1397c478bd9Sstevel@tonic-gate %/* Remove entry with the specified hashvalue, key, and record number.
1407c478bd9Sstevel@tonic-gate %   Returns 'TRUE' if successful, FALSE otherwise.
1417c478bd9Sstevel@tonic-gate %   If the entry being removed is at the head of the list, then
1427c478bd9Sstevel@tonic-gate %   the head is updated to reflect the removal. The storage for the index
1437c478bd9Sstevel@tonic-gate %   entry is freed. The record pointed to by 'recnum' must be removed
1447c478bd9Sstevel@tonic-gate %   through another means.  All that is updated in this operation is the
1457c478bd9Sstevel@tonic-gate %   index. */
1467c478bd9Sstevel@tonic-gate %  bool_t remove( db_index_entry **, bool_t, unsigned long, item *, entryp );
1477c478bd9Sstevel@tonic-gate %
1487c478bd9Sstevel@tonic-gate %/* Replace the 'location' field of the index entry with the given one. */
1497c478bd9Sstevel@tonic-gate %  void replace( entryp ep ) {location = ep;}
1507c478bd9Sstevel@tonic-gate %
1517c478bd9Sstevel@tonic-gate %/* Create and add an entry with the given hashvalue, key value, and record
1527c478bd9Sstevel@tonic-gate %   location, to the bucket pointed to by 'hashvalue'.
1537c478bd9Sstevel@tonic-gate %   If an entry with the same identical information is found, no addition
1547c478bd9Sstevel@tonic-gate %   is done.  If an entry with the same hashvalue and key value is found,
1557c478bd9Sstevel@tonic-gate %   the entry is added after the first entry with this property.  Otherwise,
1567c478bd9Sstevel@tonic-gate %   the entry is added to the head of the bucket.  This way, entries
1577c478bd9Sstevel@tonic-gate %   with the same hashvalue and key are not scattered throughout the bucket
1587c478bd9Sstevel@tonic-gate %   but they occur together. Copy is made of given key. */
1597c478bd9Sstevel@tonic-gate %  bool_t add( db_index_entry **oldhead, bool_t, unsigned long hval, item *,
1607c478bd9Sstevel@tonic-gate %	    entryp );
1617c478bd9Sstevel@tonic-gate %
1627c478bd9Sstevel@tonic-gate %/* Print this entry to stdout. */
1637c478bd9Sstevel@tonic-gate %  void print();
1647c478bd9Sstevel@tonic-gate %
1657c478bd9Sstevel@tonic-gate %/* Print bucket starting with this entry. */
1667c478bd9Sstevel@tonic-gate %  void print_all();
1677c478bd9Sstevel@tonic-gate %
1687c478bd9Sstevel@tonic-gate %/* Print result list starting with this entry. */
1697c478bd9Sstevel@tonic-gate %  void print_results();
1707c478bd9Sstevel@tonic-gate %};
1717c478bd9Sstevel@tonic-gate %typedef class db_index_entry * db_index_entry_p;
172*a506a34cSth160488 #endif /* RPC_HDR */
173*a506a34cSth160488 #endif /* USINGC */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #if RPC_HDR
176*a506a34cSth160488 %#endif /* _DB_INDEX_ENTRY_H */
177*a506a34cSth160488 #endif /* RPC_HDR */
178