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