wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using u8 = System.Byte; |
2 | using u32 = System.UInt32; |
||
3 | |||
4 | namespace Community.CsharpSqlite |
||
5 | { |
||
6 | public partial class Sqlite3 |
||
7 | { |
||
8 | /* |
||
9 | ** 2001 September 22 |
||
10 | ** |
||
11 | ** The author disclaims copyright to this source code. In place of |
||
12 | ** a legal notice, here is a blessing: |
||
13 | ** |
||
14 | ** May you do good and not evil. |
||
15 | ** May you find forgiveness for yourself and forgive others. |
||
16 | ** May you share freely, never taking more than you give. |
||
17 | ** |
||
18 | ************************************************************************* |
||
19 | ** This is the header file for the generic hash-table implemenation |
||
20 | ** used in SQLite. |
||
21 | ************************************************************************* |
||
22 | ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart |
||
23 | ** C#-SQLite is an independent reimplementation of the SQLite software library |
||
24 | ** |
||
25 | ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3 |
||
26 | ** |
||
27 | ************************************************************************* |
||
28 | */ |
||
29 | //#if !_SQLITE_HASH_H_ |
||
30 | //#define _SQLITE_HASH_H_ |
||
31 | |||
32 | /* Forward declarations of structures. */ |
||
33 | //typedef struct Hash Hash; |
||
34 | //typedef struct HashElem HashElem; |
||
35 | |||
36 | /* A complete hash table is an instance of the following structure. |
||
37 | ** The internals of this structure are intended to be opaque -- client |
||
38 | ** code should not attempt to access or modify the fields of this structure |
||
39 | ** directly. Change this structure only by using the routines below. |
||
40 | ** However, some of the "procedures" and "functions" for modifying and |
||
41 | ** accessing this structure are really macros, so we can't really make |
||
42 | ** this structure opaque. |
||
43 | ** |
||
44 | ** All elements of the hash table are on a single doubly-linked list. |
||
45 | ** Hash.first points to the head of this list. |
||
46 | ** |
||
47 | ** There are Hash.htsize buckets. Each bucket points to a spot in |
||
48 | ** the global doubly-linked list. The contents of the bucket are the |
||
49 | ** element pointed to plus the next _ht.count-1 elements in the list. |
||
50 | ** |
||
51 | ** Hash.htsize and Hash.ht may be zero. In that case lookup is done |
||
52 | ** by a linear search of the global list. For small tables, the |
||
53 | ** Hash.ht table is never allocated because if there are few elements |
||
54 | ** in the table, it is faster to do a linear search than to manage |
||
55 | ** the hash table. |
||
56 | */ |
||
57 | public class _ht |
||
58 | { /* the hash table */ |
||
59 | public int count; /* Number of entries with this hash */ |
||
60 | public HashElem chain; /* Pointer to first entry with this hash */ |
||
61 | }; |
||
62 | |||
63 | public class Hash |
||
64 | { |
||
65 | public u32 htsize = 31; /* Number of buckets in the hash table */ |
||
66 | public u32 count; /* Number of entries in this table */ |
||
67 | public HashElem first; /* The first element of the array */ |
||
68 | public _ht[] ht; |
||
69 | public Hash Copy() |
||
70 | { |
||
71 | if ( this == null ) |
||
72 | return null; |
||
73 | else |
||
74 | { |
||
75 | Hash cp = (Hash)MemberwiseClone(); |
||
76 | return cp; |
||
77 | } |
||
78 | } |
||
79 | }; |
||
80 | |||
81 | /* Each element in the hash table is an instance of the following |
||
82 | ** structure. All elements are stored on a single doubly-linked list. |
||
83 | ** |
||
84 | ** Again, this structure is intended to be opaque, but it can't really |
||
85 | ** be opaque because it is used by macros. |
||
86 | */ |
||
87 | public class HashElem |
||
88 | { |
||
89 | public HashElem next; |
||
90 | public HashElem prev; /* Next and previous elements in the table */ |
||
91 | public object data; /* Data associated with this element */ |
||
92 | public string pKey; |
||
93 | public int nKey; /* Key associated with this element */ |
||
94 | }; |
||
95 | |||
96 | /* |
||
97 | ** Access routines. To delete, insert a NULL pointer. |
||
98 | */ |
||
99 | //void sqlite3HashInit(Hash); |
||
100 | //void *sqlite3HashInsert(Hash*, string pKey, int nKey, object *pData); |
||
101 | //void *sqlite3HashFind(const Hash*, string pKey, int nKey); |
||
102 | //void sqlite3HashClear(Hash); |
||
103 | |||
104 | /* |
||
105 | ** Macros for looping over all elements of a hash table. The idiom is |
||
106 | ** like this: |
||
107 | ** |
||
108 | ** Hash h; |
||
109 | ** HashElem p; |
||
110 | ** ... |
||
111 | ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){ |
||
112 | ** SomeStructure pData = sqliteHashData(p); |
||
113 | ** // do something with pData |
||
114 | ** } |
||
115 | */ |
||
116 | //#define sqliteHashFirst(H) ((H).first) |
||
117 | static HashElem sqliteHashFirst( Hash H ) |
||
118 | { |
||
119 | return H.first; |
||
120 | } |
||
121 | //#define sqliteHashNext(E) ((E).next) |
||
122 | static HashElem sqliteHashNext( HashElem E ) |
||
123 | { |
||
124 | return E.next; |
||
125 | } |
||
126 | //#define sqliteHashData(E) ((E).data) |
||
127 | static object sqliteHashData( HashElem E ) |
||
128 | { |
||
129 | return E.data; |
||
130 | } |
||
131 | /* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */ |
||
132 | /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ |
||
133 | |||
134 | /* |
||
135 | ** Number of entries in a hash table |
||
136 | */ |
||
137 | /* #define sqliteHashCount(H) ((H)->count) // NOT USED */ |
||
138 | |||
139 | //#endif // * _SQLITE_HASH_H_ */ |
||
140 | } |
||
141 | } |