xref: /titanic_51/usr/src/lib/libnisdb/db_index_c.x (revision a87701e9837f8a9ee9e4c4d3186295c0e29f743f)
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
5d67944fbSScott Rotondo  * Common Development and Distribution License (the "License").
6d67944fbSScott 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*a87701e9SGary Mills  *  Copyright 2015 Gary Mills
25d67944fbSScott Rotondo  *  Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  *  Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
29*a87701e9SGary Mills #if RPC_XDR
30*a87701e9SGary Mills %#include "ldap_xdr.h"
31*a87701e9SGary Mills #endif /* RPC_XDR */
32*a87701e9SGary Mills 
337c478bd9Sstevel@tonic-gate #if RPC_HDR
347c478bd9Sstevel@tonic-gate %#ifndef _DB_INDEX_H
357c478bd9Sstevel@tonic-gate %#define _DB_INDEX_H
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate %
387c478bd9Sstevel@tonic-gate %/* db_index is a hash table with separate overflow buckets. */
397c478bd9Sstevel@tonic-gate %
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef USINGC
437c478bd9Sstevel@tonic-gate %#include "db_item_c.h"
447c478bd9Sstevel@tonic-gate %#include "db_index_entry_c.h"
457c478bd9Sstevel@tonic-gate %#include "db_table_c.h"
467c478bd9Sstevel@tonic-gate %#include "db_scheme_c.h"
477c478bd9Sstevel@tonic-gate #else
487c478bd9Sstevel@tonic-gate %#include "db_item.h"
497c478bd9Sstevel@tonic-gate %#include "db_index_entry.h"
507c478bd9Sstevel@tonic-gate %#include "db_table.h"
517c478bd9Sstevel@tonic-gate %#include "db_scheme.h"
52a506a34cSth160488 #endif /* USINGC */
53a506a34cSth160488 #endif /* RPC_HDR */
547c478bd9Sstevel@tonic-gate %
557c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h"
567c478bd9Sstevel@tonic-gate %
577c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
587c478bd9Sstevel@tonic-gate #ifdef USINGC
597c478bd9Sstevel@tonic-gate struct db_index {
607c478bd9Sstevel@tonic-gate   db_index_entry_p tab<>;
617c478bd9Sstevel@tonic-gate   int count;
627c478bd9Sstevel@tonic-gate   bool case_insens;
637c478bd9Sstevel@tonic-gate   __nisdb_rwlock_t index_rwlock;
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate typedef struct db_index * db_index_p;
66a506a34cSth160488 #endif /* USINGC */
67a506a34cSth160488 #endif /* RPC_HDR */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #ifndef USINGC
707c478bd9Sstevel@tonic-gate #ifdef RPC_HDR
717c478bd9Sstevel@tonic-gate %class db_index  {
727c478bd9Sstevel@tonic-gate %  long table_size;
737c478bd9Sstevel@tonic-gate %  db_index_entry_p *tab;
747c478bd9Sstevel@tonic-gate %  int count;
757c478bd9Sstevel@tonic-gate %  bool_t case_insens;
767c478bd9Sstevel@tonic-gate %  STRUCTRWLOCK(index);
777c478bd9Sstevel@tonic-gate %
787c478bd9Sstevel@tonic-gate %/* Grow the current hashtable upto the next size.
797c478bd9Sstevel@tonic-gate %   The contents of the existing hashtable is copied to the new one and
807c478bd9Sstevel@tonic-gate %   relocated according to its hashvalue relative to the new size.
817c478bd9Sstevel@tonic-gate %   Old table is deleted after the relocation. */
827c478bd9Sstevel@tonic-gate %  void grow();
837c478bd9Sstevel@tonic-gate %
847c478bd9Sstevel@tonic-gate %/* Clear the chains created in db_index_entrys */
857c478bd9Sstevel@tonic-gate %/*  void clear_results();*/
867c478bd9Sstevel@tonic-gate % public:
877c478bd9Sstevel@tonic-gate %
887c478bd9Sstevel@tonic-gate %/* Constructor: creates empty index. */
897c478bd9Sstevel@tonic-gate %  db_index();
907c478bd9Sstevel@tonic-gate %
917c478bd9Sstevel@tonic-gate %/* Constructor: creates index by loading it from the specified file.
927c478bd9Sstevel@tonic-gate %   If loading fails, creates empty index. */
937c478bd9Sstevel@tonic-gate %  db_index( char *);
947c478bd9Sstevel@tonic-gate %
957c478bd9Sstevel@tonic-gate %/* Destructor: deletes index, including all associated db_index_entry. */
967c478bd9Sstevel@tonic-gate %  ~db_index();
977c478bd9Sstevel@tonic-gate %
987c478bd9Sstevel@tonic-gate %/* Empty table (deletes index, including all associated db_index_entry) */
997c478bd9Sstevel@tonic-gate %  void reset();
1007c478bd9Sstevel@tonic-gate %
1017c478bd9Sstevel@tonic-gate %/* Initialize index according to the specification of the key descriptor.
1027c478bd9Sstevel@tonic-gate %   Currently, only affects case_insens flag of index. */
1037c478bd9Sstevel@tonic-gate %  void init( db_key_desc * );
1047c478bd9Sstevel@tonic-gate %
1057c478bd9Sstevel@tonic-gate %/* Moves an index from an xdr index */
106d67944fbSScott Rotondo %  db_status move_xdr_db_index(db_index *orig);
1077c478bd9Sstevel@tonic-gate %
1087c478bd9Sstevel@tonic-gate %/* Dumps this index to named file. */
1097c478bd9Sstevel@tonic-gate %  int dump( char *);
1107c478bd9Sstevel@tonic-gate %
1117c478bd9Sstevel@tonic-gate %
1127c478bd9Sstevel@tonic-gate %/* Look up given index value in hashtable.
1137c478bd9Sstevel@tonic-gate %  Return pointer to db_index_entries that match the given value, linked
1147c478bd9Sstevel@tonic-gate %  via the 'next_result' pointer.  Return in 'how_many_found' the size
1157c478bd9Sstevel@tonic-gate %  of this list. Return NULL if not found. */
1167c478bd9Sstevel@tonic-gate %  db_index_entry *lookup(item *, long *, db_table *, bool_t);
1177c478bd9Sstevel@tonic-gate %
1187c478bd9Sstevel@tonic-gate %/* Remove the entry with the given index value and location 'recnum'.
1197c478bd9Sstevel@tonic-gate %   If successful, return DB_SUCCESS; otherwise DB_NOTUNIQUE if index_value
1207c478bd9Sstevel@tonic-gate %   is null; DB_NOTFOUND if entry is not found.
1217c478bd9Sstevel@tonic-gate %   If successful, decrement count of number of entries in hash table. */
1227c478bd9Sstevel@tonic-gate %  db_status remove( item*, entryp );
1237c478bd9Sstevel@tonic-gate %
1247c478bd9Sstevel@tonic-gate %/* Add a new index entry with the given index value and location 'recnum'.
1257c478bd9Sstevel@tonic-gate %   Return DB_NOTUNIQUE, if entry with identical index_value and recnum
1267c478bd9Sstevel@tonic-gate %   already exists.  If entry is added, return DB_SUCCESS.
1277c478bd9Sstevel@tonic-gate %   Increment count of number of entries in index table and grow table
1287c478bd9Sstevel@tonic-gate %   if table is more than half full.
1297c478bd9Sstevel@tonic-gate %   Note that a copy of index_value is made for new entry. */
1307c478bd9Sstevel@tonic-gate %  db_status add( item*, entryp );
1317c478bd9Sstevel@tonic-gate %
1327c478bd9Sstevel@tonic-gate %/* Return in 'tsize' the table_size, and 'tcount' the number of entries
1337c478bd9Sstevel@tonic-gate %   in the table. */
1347c478bd9Sstevel@tonic-gate %  void stats( long* tsize, long* tcount);
1357c478bd9Sstevel@tonic-gate %
1367c478bd9Sstevel@tonic-gate %
1377c478bd9Sstevel@tonic-gate %/* Print all entries in the table. */
1387c478bd9Sstevel@tonic-gate %  void print();
1397c478bd9Sstevel@tonic-gate %
1407c478bd9Sstevel@tonic-gate %/* Locking methods */
1417c478bd9Sstevel@tonic-gate %
1427c478bd9Sstevel@tonic-gate %  int acqexcl(void) {
1437c478bd9Sstevel@tonic-gate %	return (WLOCK(index));
1447c478bd9Sstevel@tonic-gate %  }
1457c478bd9Sstevel@tonic-gate %
1467c478bd9Sstevel@tonic-gate %  int relexcl(void) {
1477c478bd9Sstevel@tonic-gate %	return (WULOCK(index));
1487c478bd9Sstevel@tonic-gate %  }
1497c478bd9Sstevel@tonic-gate %
1507c478bd9Sstevel@tonic-gate %  int acqnonexcl(void) {
1517c478bd9Sstevel@tonic-gate %	return (RLOCK(index));
1527c478bd9Sstevel@tonic-gate %  }
1537c478bd9Sstevel@tonic-gate %
1547c478bd9Sstevel@tonic-gate %  int relnonexcl(void) {
1557c478bd9Sstevel@tonic-gate %	return (RULOCK(index));
1567c478bd9Sstevel@tonic-gate %  }
1577c478bd9Sstevel@tonic-gate %};
1587c478bd9Sstevel@tonic-gate %#ifdef __cplusplus
1597c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_index(XDR *, db_index *);
1607c478bd9Sstevel@tonic-gate %#elif __STDC__
1617c478bd9Sstevel@tonic-gate %extern bool_t xdr_db_index(XDR *, db_index *);
1627c478bd9Sstevel@tonic-gate %#endif
1637c478bd9Sstevel@tonic-gate %typedef class db_index * db_index_p;
164a506a34cSth160488 #endif /* RPC_HDR */
165a506a34cSth160488 #endif /* USINGC */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #if RPC_HDR
168a506a34cSth160488 %#endif /* _DB_INDEX_H */
169a506a34cSth160488 #endif /* RPC_HDR */
170