forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMap.h
More file actions
210 lines (175 loc) · 5.94 KB
/
Copy pathHashMap.h
File metadata and controls
210 lines (175 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* Copyright (c) 2004-2020 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Tada AB
* Chapman Flack
*/
#ifndef __pljava_HashMap_h
#define __pljava_HashMap_h
#include "pljava/PgObject.h"
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************
* The HashMap class. Maintains mappings between HashKey instances
* and values. The mappings are stored in hash bucket chains
* containing Entry instances.
*
* All Entries and HashKeys will be allocated using the same
* MemoryContext as the one used when creating the HashMap.
* A HashKey used for storing (HashKey_put) is cloned so that
* the HashMap maintains its own copy.
*
* @author Thomas Hallgren
*
*************************************************************/
struct HashKey_;
typedef struct HashKey_* HashKey;
struct Iterator_;
typedef struct Iterator_* Iterator;
struct Entry_;
typedef struct Entry_* Entry;
struct HashMap_;
typedef struct HashMap_* HashMap;
/*
* Creates a new HashMap with an initial capacity. If ctx is NULL, CurrentMemoryContext
* will be used.
*/
extern HashMap HashMap_create(uint32 initialCapacity, MemoryContext ctx);
/*
* Clears the HashMap.
*/
extern void HashMap_clear(HashMap self);
/*
* Returns an iterator that iterates over the entries of
* this HashMap.
*/
extern Iterator HashMap_entries(HashMap self);
/*
* Returns the object stored using the given key or NULL if no
* such object can be found.
*/
extern void* HashMap_get(HashMap self, HashKey key);
/*
* Returns the object stored using the given null
* terminated string or NULL if no such object can be found.
*/
extern void* HashMap_getByString(HashMap self, const char* key);
/*
* Returns the object stored using the given Oid or NULL
* if no such object can be found.
*/
extern void* HashMap_getByOid(HashMap self, Oid key);
/*
* Returns the object stored using the given null
* terminated string and Oid, or NULL if no such object can be found.
*/
extern void* HashMap_getByStringOid(HashMap self, const char* string, Oid oid);
/*
* Returns the object stored using the given Opaque pointer or NULL
* if no such object can be found.
*/
extern void* HashMap_getByOpaque(HashMap self, void* key);
/*
* Stores the given value under the given key. If
* an old value was stored using this key, the old value is returned.
* Otherwise this method returns NULL.
* This method will make a private copy of the key argument.
*/
extern void* HashMap_put(HashMap self, HashKey key, void* value);
/*
* Stores the given value under the given null terminated string. If
* an old value was stored using this key, the old value is returned.
* Otherwise this method returns NULL.
*/
extern void* HashMap_putByString(HashMap self, const char* key, void* value);
/*
* Stores the given value under the given Oid. If an old value
* was stored using this key, the old value is returned. Otherwise
* this method returns NULL.
*/
extern void* HashMap_putByOid(HashMap self, Oid key, void* value);
/*
* Stores the given value under the given Opaque pointer. If an old value
* was stored using this key, the old value is returned. Otherwise
* this method returns NULL.
*/
extern void* HashMap_putByOpaque(HashMap self, void* key, void* value);
/*
* Stores the given value under the given null terminated string and oid. If
* an old value was stored using this key, the old value is returned.
* Otherwise this method returns NULL.
*/
extern void* HashMap_putByStringOid(HashMap self, const char* string, Oid oid,
void* value);
/*
* Removes the value stored under the given key. The the old value
* (if any) is returned.
*/
extern void* HashMap_remove(HashMap self, HashKey key);
/*
* Removes the value stored under the given key. The the old value
* (if any) is returned. The key associated with the value is deleted.
*/
extern void* HashMap_removeByString(HashMap self, const char* key);
/*
* Removes the value stored under the given key. The the old value
* (if any) is returned.
*/
extern void* HashMap_removeByOid(HashMap self, Oid key);
/*
* Removes the value stored under the given key. The the old value
* (if any) is returned.
*/
extern void* HashMap_removeByOpaque(HashMap self, void* key);
/*
* Removes the value stored under the given key. The the old value
* (if any) is returned. The key associated with the value is deleted.
*/
extern void* HashMap_removeByStringOid(HashMap self, const char* str, Oid oid);
/*
* Returns the number of entries currently in the HashMap
*/
extern uint32 HashMap_size(HashMap self);
/*************************************************************
* An instance of the Entry class holds a mapping between one
* HashKey and its associated value.
*************************************************************/
/*
* Returns the value of the Entry.
*/
extern void* Entry_getValue(Entry self);
/*
* Assigns a new value to the Entry. Returns the old value.
*/
extern void* Entry_setValue(Entry self, void* value);
/*
* Returns the key of the Entry. Can be used for removal.
*/
extern HashKey Entry_getKey(Entry self);
/*************************************************************
* The HashKey is an abstract class. Currently, four different
* implementations are used. Oid, Opaque (void*), String, and StringOid.
*************************************************************/
/*
* Clone the key. The clone is allocated in the given context.
*/
extern HashKey HashKey_clone(HashKey self, MemoryContext ctx);
/*
* Return true if the key is equal to another key.
*/
extern bool HashKey_equals(HashKey self, HashKey other);
/*
* Return the hash code for the key
*/
extern uint32 HashKey_hashCode(HashKey self);
#ifdef __cplusplus
} /* end of extern "C" declaration */
#endif
#endif