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 %#pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #if RPC_HDR 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate %#ifndef _DB_INDEX_ENTRY_H 347c478bd9Sstevel@tonic-gate %#define _DB_INDEX_ENTRY_H 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate % 377c478bd9Sstevel@tonic-gate % /* db_index_entry is an entry in the hashtable. db_index_entries can be 387c478bd9Sstevel@tonic-gate % linked in one of two ways: 397c478bd9Sstevel@tonic-gate % * via the 'next' pointer and form the hash bucket 407c478bd9Sstevel@tonic-gate % * via the 'nextresult' pointer and form a chain of results. 417c478bd9Sstevel@tonic-gate % Each entry contains the key, the hash value of key, and location 427c478bd9Sstevel@tonic-gate % information 'entryp' 437c478bd9Sstevel@tonic-gate % entryp is location information. 447c478bd9Sstevel@tonic-gate % It might be pointer to an in core entry, or an indirect pointer 457c478bd9Sstevel@tonic-gate % identifying the location of an entry somewhere in memory (e.g. 467c478bd9Sstevel@tonic-gate % if there was a table where all complete entries are stored) --- this 477c478bd9Sstevel@tonic-gate % is desirable, for example, for XDR operations on a multi-indexed table; 487c478bd9Sstevel@tonic-gate % or, if used in conjunction with NetISAM, it may be the record number. */ 497c478bd9Sstevel@tonic-gate %/* *** notes */ 507c478bd9Sstevel@tonic-gate %/* remember to set next_result to null first if using XDR. */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #ifdef USINGC 537c478bd9Sstevel@tonic-gate %#include "db_item_c.h" 547c478bd9Sstevel@tonic-gate %#include "db_table_c.h" /* contains definition of entryp */ 557c478bd9Sstevel@tonic-gate %typedef void *nullptr; 567c478bd9Sstevel@tonic-gate #else 577c478bd9Sstevel@tonic-gate %#include "db_item.h" 587c478bd9Sstevel@tonic-gate %#include "db_table.h" /* contains definition of entryp */ 59*a506a34cSth160488 #endif /* USIGNC */ 60*a506a34cSth160488 #endif /* RPC_HDR */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 647c478bd9Sstevel@tonic-gate #ifdef USINGC 657c478bd9Sstevel@tonic-gate struct db_index_entry { 667c478bd9Sstevel@tonic-gate unsigned long hashval; 677c478bd9Sstevel@tonic-gate item *key; 687c478bd9Sstevel@tonic-gate entryp location; 697c478bd9Sstevel@tonic-gate db_index_entry* next; 707c478bd9Sstevel@tonic-gate #ifdef USINGC 717c478bd9Sstevel@tonic-gate nullptr next_result; 727c478bd9Sstevel@tonic-gate #else 737c478bd9Sstevel@tonic-gate db_index_entry* next_result; 747c478bd9Sstevel@tonic-gate #endif 757c478bd9Sstevel@tonic-gate }; 767c478bd9Sstevel@tonic-gate typedef struct db_index_entry * db_index_entry_p; 77*a506a34cSth160488 #endif /* USINGC */ 78*a506a34cSth160488 #endif /* RPC_HDR */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #ifndef USINGC 817c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 827c478bd9Sstevel@tonic-gate %class db_index_entry { 837c478bd9Sstevel@tonic-gate % unsigned long hashval; 847c478bd9Sstevel@tonic-gate % item *key; 857c478bd9Sstevel@tonic-gate % entryp location; 867c478bd9Sstevel@tonic-gate % db_index_entry* next; 877c478bd9Sstevel@tonic-gate % db_index_entry* next_result; 887c478bd9Sstevel@tonic-gate % public: 897c478bd9Sstevel@tonic-gate % 907c478bd9Sstevel@tonic-gate %/* Constructor: create an entry using given string and location info. */ 917c478bd9Sstevel@tonic-gate % db_index_entry( char* name, int nlen, entryp location ); 927c478bd9Sstevel@tonic-gate % 937c478bd9Sstevel@tonic-gate %/* Constructor: create an entry using the given info. 947c478bd9Sstevel@tonic-gate % A copy of the key is made. New entry is added to head of list of 'n'. */ 957c478bd9Sstevel@tonic-gate % db_index_entry( unsigned long hval, item *, entryp, db_index_entry *n); 967c478bd9Sstevel@tonic-gate % 977c478bd9Sstevel@tonic-gate %/* Destructor: deletes key and itself. Assumes that deletion of 987c478bd9Sstevel@tonic-gate % object at location is done elsewhere (beforehand) */ 997c478bd9Sstevel@tonic-gate % ~db_index_entry() {delete key; } 1007c478bd9Sstevel@tonic-gate % 1017c478bd9Sstevel@tonic-gate %/* Relocate bucket starting with this entry to new hashtable 'new_tab'. */ 1027c478bd9Sstevel@tonic-gate % void relocate( db_index_entry**, unsigned long ); 1037c478bd9Sstevel@tonic-gate % 1047c478bd9Sstevel@tonic-gate %/* Join two lists (entry as identified by its 'location' occurs on both list, 1057c478bd9Sstevel@tonic-gate % then it is included in the list returned). 1067c478bd9Sstevel@tonic-gate % Returns pointer to resulting list; size of list 1077c478bd9Sstevel@tonic-gate % returned in 'newsize'. List is chained using the 'nextresult' pointer. */ 1087c478bd9Sstevel@tonic-gate % db_index_entry* join( long size1, long size2, db_index_entry *list2, 1097c478bd9Sstevel@tonic-gate % long * newsize ); 1107c478bd9Sstevel@tonic-gate % 1117c478bd9Sstevel@tonic-gate %/* Returns pointer to a list of index entries with the same hash value and 1127c478bd9Sstevel@tonic-gate % key as those given. Returns in 'how_many' the number of entries in the 1137c478bd9Sstevel@tonic-gate % list returned. The list is linked by the 'next_result' field of the 1147c478bd9Sstevel@tonic-gate % index entries. These may be changed after the next call to 'lookup' 1157c478bd9Sstevel@tonic-gate % or 'join'. */ 1167c478bd9Sstevel@tonic-gate % db_index_entry* lookup( bool_t, unsigned long, item*, long *); 1177c478bd9Sstevel@tonic-gate % 1187c478bd9Sstevel@tonic-gate %/* Return pointer to index entry with same hash value, same key, 1197c478bd9Sstevel@tonic-gate % and same record number as those supplied. Returns NULL if not found. */ 1207c478bd9Sstevel@tonic-gate % db_index_entry* lookup( bool_t, unsigned long, item*, entryp ); //name entry 1217c478bd9Sstevel@tonic-gate % 1227c478bd9Sstevel@tonic-gate %/* Return the next entry in the bucket starting with this entry 1237c478bd9Sstevel@tonic-gate % with the same hashvalue, key and location as this entry. */ 1247c478bd9Sstevel@tonic-gate % db_index_entry* getnext( bool_t, unsigned long, item*, entryp ); 1257c478bd9Sstevel@tonic-gate % 1267c478bd9Sstevel@tonic-gate %/* Return the next entry in the bucket. */ 1277c478bd9Sstevel@tonic-gate % db_index_entry* getnextentry() {return next;} 1287c478bd9Sstevel@tonic-gate % 1297c478bd9Sstevel@tonic-gate %/* Return the next entry in the 'next_result' chain. */ 1307c478bd9Sstevel@tonic-gate % db_index_entry* getnextresult() {return next_result;} 1317c478bd9Sstevel@tonic-gate % 1327c478bd9Sstevel@tonic-gate %/* Return the location field of this entry. */ 1337c478bd9Sstevel@tonic-gate % entryp getlocation() {return location;} 1347c478bd9Sstevel@tonic-gate % 1357c478bd9Sstevel@tonic-gate %/* Assign the given pointer as the next result after this entry. */ 1367c478bd9Sstevel@tonic-gate % void addresult( db_index_entry * nr ) { next_result = nr; } 1377c478bd9Sstevel@tonic-gate % 1387c478bd9Sstevel@tonic-gate %/* Return the pointer to the key of this entry. */ 1397c478bd9Sstevel@tonic-gate % item * get_key() {return key;} 1407c478bd9Sstevel@tonic-gate % 1417c478bd9Sstevel@tonic-gate %/* Remove entry with the specified hashvalue, key, and record number. 1427c478bd9Sstevel@tonic-gate % Returns 'TRUE' if successful, FALSE otherwise. 1437c478bd9Sstevel@tonic-gate % If the entry being removed is at the head of the list, then 1447c478bd9Sstevel@tonic-gate % the head is updated to reflect the removal. The storage for the index 1457c478bd9Sstevel@tonic-gate % entry is freed. The record pointed to by 'recnum' must be removed 1467c478bd9Sstevel@tonic-gate % through another means. All that is updated in this operation is the 1477c478bd9Sstevel@tonic-gate % index. */ 1487c478bd9Sstevel@tonic-gate % bool_t remove( db_index_entry **, bool_t, unsigned long, item *, entryp ); 1497c478bd9Sstevel@tonic-gate % 1507c478bd9Sstevel@tonic-gate %/* Replace the 'location' field of the index entry with the given one. */ 1517c478bd9Sstevel@tonic-gate % void replace( entryp ep ) {location = ep;} 1527c478bd9Sstevel@tonic-gate % 1537c478bd9Sstevel@tonic-gate %/* Create and add an entry with the given hashvalue, key value, and record 1547c478bd9Sstevel@tonic-gate % location, to the bucket pointed to by 'hashvalue'. 1557c478bd9Sstevel@tonic-gate % If an entry with the same identical information is found, no addition 1567c478bd9Sstevel@tonic-gate % is done. If an entry with the same hashvalue and key value is found, 1577c478bd9Sstevel@tonic-gate % the entry is added after the first entry with this property. Otherwise, 1587c478bd9Sstevel@tonic-gate % the entry is added to the head of the bucket. This way, entries 1597c478bd9Sstevel@tonic-gate % with the same hashvalue and key are not scattered throughout the bucket 1607c478bd9Sstevel@tonic-gate % but they occur together. Copy is made of given key. */ 1617c478bd9Sstevel@tonic-gate % bool_t add( db_index_entry **oldhead, bool_t, unsigned long hval, item *, 1627c478bd9Sstevel@tonic-gate % entryp ); 1637c478bd9Sstevel@tonic-gate % 1647c478bd9Sstevel@tonic-gate %/* Print this entry to stdout. */ 1657c478bd9Sstevel@tonic-gate % void print(); 1667c478bd9Sstevel@tonic-gate % 1677c478bd9Sstevel@tonic-gate %/* Print bucket starting with this entry. */ 1687c478bd9Sstevel@tonic-gate % void print_all(); 1697c478bd9Sstevel@tonic-gate % 1707c478bd9Sstevel@tonic-gate %/* Print result list starting with this entry. */ 1717c478bd9Sstevel@tonic-gate % void print_results(); 1727c478bd9Sstevel@tonic-gate %}; 1737c478bd9Sstevel@tonic-gate %typedef class db_index_entry * db_index_entry_p; 174*a506a34cSth160488 #endif /* RPC_HDR */ 175*a506a34cSth160488 #endif /* USINGC */ 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #if RPC_HDR 178*a506a34cSth160488 %#endif /* _DB_INDEX_ENTRY_H */ 179*a506a34cSth160488 #endif /* RPC_HDR */ 180