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 5*d67944fbSScott Rotondo * Common Development and Distribution License (the "License"). 6*d67944fbSScott Rotondo * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 227c478bd9Sstevel@tonic-gate * db_index_c.x 237c478bd9Sstevel@tonic-gate * 24*d67944fbSScott Rotondo * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #if RPC_HDR 297c478bd9Sstevel@tonic-gate %#ifndef _DB_INDEX_H 307c478bd9Sstevel@tonic-gate %#define _DB_INDEX_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate % 337c478bd9Sstevel@tonic-gate %/* db_index is a hash table with separate overflow buckets. */ 347c478bd9Sstevel@tonic-gate % 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef USINGC 387c478bd9Sstevel@tonic-gate %#include "db_item_c.h" 397c478bd9Sstevel@tonic-gate %#include "db_index_entry_c.h" 407c478bd9Sstevel@tonic-gate %#include "db_table_c.h" 417c478bd9Sstevel@tonic-gate %#include "db_scheme_c.h" 427c478bd9Sstevel@tonic-gate #else 437c478bd9Sstevel@tonic-gate %#include "db_item.h" 447c478bd9Sstevel@tonic-gate %#include "db_index_entry.h" 457c478bd9Sstevel@tonic-gate %#include "db_table.h" 467c478bd9Sstevel@tonic-gate %#include "db_scheme.h" 47a506a34cSth160488 #endif /* USINGC */ 48a506a34cSth160488 #endif /* RPC_HDR */ 497c478bd9Sstevel@tonic-gate % 507c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h" 517c478bd9Sstevel@tonic-gate % 527c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 537c478bd9Sstevel@tonic-gate #ifdef USINGC 547c478bd9Sstevel@tonic-gate struct db_index { 557c478bd9Sstevel@tonic-gate db_index_entry_p tab<>; 567c478bd9Sstevel@tonic-gate int count; 577c478bd9Sstevel@tonic-gate bool case_insens; 587c478bd9Sstevel@tonic-gate __nisdb_rwlock_t index_rwlock; 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate typedef struct db_index * db_index_p; 61a506a34cSth160488 #endif /* USINGC */ 62a506a34cSth160488 #endif /* RPC_HDR */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #ifndef USINGC 657c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 667c478bd9Sstevel@tonic-gate %class db_index { 677c478bd9Sstevel@tonic-gate % long table_size; 687c478bd9Sstevel@tonic-gate % db_index_entry_p *tab; 697c478bd9Sstevel@tonic-gate % int count; 707c478bd9Sstevel@tonic-gate % bool_t case_insens; 717c478bd9Sstevel@tonic-gate % STRUCTRWLOCK(index); 727c478bd9Sstevel@tonic-gate % 737c478bd9Sstevel@tonic-gate %/* Grow the current hashtable upto the next size. 747c478bd9Sstevel@tonic-gate % The contents of the existing hashtable is copied to the new one and 757c478bd9Sstevel@tonic-gate % relocated according to its hashvalue relative to the new size. 767c478bd9Sstevel@tonic-gate % Old table is deleted after the relocation. */ 777c478bd9Sstevel@tonic-gate % void grow(); 787c478bd9Sstevel@tonic-gate % 797c478bd9Sstevel@tonic-gate %/* Clear the chains created in db_index_entrys */ 807c478bd9Sstevel@tonic-gate %/* void clear_results();*/ 817c478bd9Sstevel@tonic-gate % public: 827c478bd9Sstevel@tonic-gate % 837c478bd9Sstevel@tonic-gate %/* Constructor: creates empty index. */ 847c478bd9Sstevel@tonic-gate % db_index(); 857c478bd9Sstevel@tonic-gate % 867c478bd9Sstevel@tonic-gate %/* Constructor: creates index by loading it from the specified file. 877c478bd9Sstevel@tonic-gate % If loading fails, creates empty index. */ 887c478bd9Sstevel@tonic-gate % db_index( char *); 897c478bd9Sstevel@tonic-gate % 907c478bd9Sstevel@tonic-gate %/* Destructor: deletes index, including all associated db_index_entry. */ 917c478bd9Sstevel@tonic-gate % ~db_index(); 927c478bd9Sstevel@tonic-gate % 937c478bd9Sstevel@tonic-gate %/* Empty table (deletes index, including all associated db_index_entry) */ 947c478bd9Sstevel@tonic-gate % void reset(); 957c478bd9Sstevel@tonic-gate % 967c478bd9Sstevel@tonic-gate %/* Initialize index according to the specification of the key descriptor. 977c478bd9Sstevel@tonic-gate % Currently, only affects case_insens flag of index. */ 987c478bd9Sstevel@tonic-gate % void init( db_key_desc * ); 997c478bd9Sstevel@tonic-gate % 1007c478bd9Sstevel@tonic-gate %/* Moves an index from an xdr index */ 101*d67944fbSScott Rotondo % db_status move_xdr_db_index(db_index *orig); 1027c478bd9Sstevel@tonic-gate % 1037c478bd9Sstevel@tonic-gate %/* Dumps this index to named file. */ 1047c478bd9Sstevel@tonic-gate % int dump( char *); 1057c478bd9Sstevel@tonic-gate % 1067c478bd9Sstevel@tonic-gate % 1077c478bd9Sstevel@tonic-gate %/* Look up given index value in hashtable. 1087c478bd9Sstevel@tonic-gate % Return pointer to db_index_entries that match the given value, linked 1097c478bd9Sstevel@tonic-gate % via the 'next_result' pointer. Return in 'how_many_found' the size 1107c478bd9Sstevel@tonic-gate % of this list. Return NULL if not found. */ 1117c478bd9Sstevel@tonic-gate % db_index_entry *lookup(item *, long *, db_table *, bool_t); 1127c478bd9Sstevel@tonic-gate % 1137c478bd9Sstevel@tonic-gate %/* Remove the entry with the given index value and location 'recnum'. 1147c478bd9Sstevel@tonic-gate % If successful, return DB_SUCCESS; otherwise DB_NOTUNIQUE if index_value 1157c478bd9Sstevel@tonic-gate % is null; DB_NOTFOUND if entry is not found. 1167c478bd9Sstevel@tonic-gate % If successful, decrement count of number of entries in hash table. */ 1177c478bd9Sstevel@tonic-gate % db_status remove( item*, entryp ); 1187c478bd9Sstevel@tonic-gate % 1197c478bd9Sstevel@tonic-gate %/* Add a new index entry with the given index value and location 'recnum'. 1207c478bd9Sstevel@tonic-gate % Return DB_NOTUNIQUE, if entry with identical index_value and recnum 1217c478bd9Sstevel@tonic-gate % already exists. If entry is added, return DB_SUCCESS. 1227c478bd9Sstevel@tonic-gate % Increment count of number of entries in index table and grow table 1237c478bd9Sstevel@tonic-gate % if table is more than half full. 1247c478bd9Sstevel@tonic-gate % Note that a copy of index_value is made for new entry. */ 1257c478bd9Sstevel@tonic-gate % db_status add( item*, entryp ); 1267c478bd9Sstevel@tonic-gate % 1277c478bd9Sstevel@tonic-gate %/* Return in 'tsize' the table_size, and 'tcount' the number of entries 1287c478bd9Sstevel@tonic-gate % in the table. */ 1297c478bd9Sstevel@tonic-gate % void stats( long* tsize, long* tcount); 1307c478bd9Sstevel@tonic-gate % 1317c478bd9Sstevel@tonic-gate % 1327c478bd9Sstevel@tonic-gate %/* Print all entries in the table. */ 1337c478bd9Sstevel@tonic-gate % void print(); 1347c478bd9Sstevel@tonic-gate % 1357c478bd9Sstevel@tonic-gate %/* Locking methods */ 1367c478bd9Sstevel@tonic-gate % 1377c478bd9Sstevel@tonic-gate % int acqexcl(void) { 1387c478bd9Sstevel@tonic-gate % return (WLOCK(index)); 1397c478bd9Sstevel@tonic-gate % } 1407c478bd9Sstevel@tonic-gate % 1417c478bd9Sstevel@tonic-gate % int relexcl(void) { 1427c478bd9Sstevel@tonic-gate % return (WULOCK(index)); 1437c478bd9Sstevel@tonic-gate % } 1447c478bd9Sstevel@tonic-gate % 1457c478bd9Sstevel@tonic-gate % int acqnonexcl(void) { 1467c478bd9Sstevel@tonic-gate % return (RLOCK(index)); 1477c478bd9Sstevel@tonic-gate % } 1487c478bd9Sstevel@tonic-gate % 1497c478bd9Sstevel@tonic-gate % int relnonexcl(void) { 1507c478bd9Sstevel@tonic-gate % return (RULOCK(index)); 1517c478bd9Sstevel@tonic-gate % } 1527c478bd9Sstevel@tonic-gate %}; 1537c478bd9Sstevel@tonic-gate %#ifdef __cplusplus 1547c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_index(XDR *, db_index *); 1557c478bd9Sstevel@tonic-gate %#elif __STDC__ 1567c478bd9Sstevel@tonic-gate %extern bool_t xdr_db_index(XDR *, db_index *); 1577c478bd9Sstevel@tonic-gate %#endif 1587c478bd9Sstevel@tonic-gate %typedef class db_index * db_index_p; 159a506a34cSth160488 #endif /* RPC_HDR */ 160a506a34cSth160488 #endif /* USINGC */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #if RPC_HDR 163a506a34cSth160488 %#endif /* _DB_INDEX_H */ 164a506a34cSth160488 #endif /* RPC_HDR */ 165