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