xref: /titanic_41/usr/src/lib/libnisdb/db_index_c.x (revision 9dd828891378a0a6a509ab601b4c5c20ca5562ec)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	db_index_c.x
24  *
25  *  Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  *  Use is subject to license terms.
27  */
28 
29 %#pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #if RPC_HDR
32 %#ifndef _DB_INDEX_H
33 %#define _DB_INDEX_H
34 
35 %
36 %/* db_index is a hash table with separate overflow buckets. */
37 %
38 
39 
40 #ifdef USINGC
41 %#include "db_item_c.h"
42 %#include "db_index_entry_c.h"
43 %#include "db_table_c.h"
44 %#include "db_scheme_c.h"
45 #else
46 %#include "db_item.h"
47 %#include "db_index_entry.h"
48 %#include "db_table.h"
49 %#include "db_scheme.h"
50 #endif /* USINGC */
51 #endif /* RPC_HDR */
52 %
53 %#include "nisdb_rw.h"
54 %
55 #if RPC_HDR || RPC_XDR
56 #ifdef USINGC
57 struct db_index {
58   db_index_entry_p tab<>;
59   int count;
60   bool case_insens;
61   __nisdb_rwlock_t index_rwlock;
62 };
63 typedef struct db_index * db_index_p;
64 #endif /* USINGC */
65 #endif /* RPC_HDR */
66 
67 #ifndef USINGC
68 #ifdef RPC_HDR
69 %class db_index  {
70 %  long table_size;
71 %  db_index_entry_p *tab;
72 %  int count;
73 %  bool_t case_insens;
74 %  STRUCTRWLOCK(index);
75 %
76 %/* Grow the current hashtable upto the next size.
77 %   The contents of the existing hashtable is copied to the new one and
78 %   relocated according to its hashvalue relative to the new size.
79 %   Old table is deleted after the relocation. */
80 %  void grow();
81 %
82 %/* Clear the chains created in db_index_entrys */
83 %/*  void clear_results();*/
84 % public:
85 %
86 %/* Constructor: creates empty index. */
87 %  db_index();
88 %
89 %/* Constructor: creates index by loading it from the specified file.
90 %   If loading fails, creates empty index. */
91 %  db_index( char *);
92 %
93 %/* Destructor: deletes index, including all associated db_index_entry. */
94 %  ~db_index();
95 %
96 %/* Empty table (deletes index, including all associated db_index_entry) */
97 %  void reset();
98 %
99 %/* Initialize index according to the specification of the key descriptor.
100 %   Currently, only affects case_insens flag of index. */
101 %  void init( db_key_desc * );
102 %
103 %/* Moves an index from an xdr index */
104 %  db_status db_index::move_xdr_db_index(db_index *orig);
105 %
106 %/* Dumps this index to named file. */
107 %  int dump( char *);
108 %
109 %
110 %/* Look up given index value in hashtable.
111 %  Return pointer to db_index_entries that match the given value, linked
112 %  via the 'next_result' pointer.  Return in 'how_many_found' the size
113 %  of this list. Return NULL if not found. */
114 %  db_index_entry *lookup(item *, long *, db_table *, bool_t);
115 %
116 %/* Remove the entry with the given index value and location 'recnum'.
117 %   If successful, return DB_SUCCESS; otherwise DB_NOTUNIQUE if index_value
118 %   is null; DB_NOTFOUND if entry is not found.
119 %   If successful, decrement count of number of entries in hash table. */
120 %  db_status remove( item*, entryp );
121 %
122 %/* Add a new index entry with the given index value and location 'recnum'.
123 %   Return DB_NOTUNIQUE, if entry with identical index_value and recnum
124 %   already exists.  If entry is added, return DB_SUCCESS.
125 %   Increment count of number of entries in index table and grow table
126 %   if table is more than half full.
127 %   Note that a copy of index_value is made for new entry. */
128 %  db_status add( item*, entryp );
129 %
130 %/* Return in 'tsize' the table_size, and 'tcount' the number of entries
131 %   in the table. */
132 %  void stats( long* tsize, long* tcount);
133 %
134 %
135 %/* Print all entries in the table. */
136 %  void print();
137 %
138 %/* Locking methods */
139 %
140 %  int acqexcl(void) {
141 %	return (WLOCK(index));
142 %  }
143 %
144 %  int relexcl(void) {
145 %	return (WULOCK(index));
146 %  }
147 %
148 %  int acqnonexcl(void) {
149 %	return (RLOCK(index));
150 %  }
151 %
152 %  int relnonexcl(void) {
153 %	return (RULOCK(index));
154 %  }
155 %};
156 %#ifdef __cplusplus
157 %extern "C" bool_t xdr_db_index(XDR *, db_index *);
158 %#elif __STDC__
159 %extern bool_t xdr_db_index(XDR *, db_index *);
160 %#endif
161 %typedef class db_index * db_index_p;
162 #endif /* RPC_HDR */
163 #endif /* USINGC */
164 
165 #if RPC_HDR
166 %#endif /* _DB_INDEX_H */
167 #endif /* RPC_HDR */
168