-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathHashMap_priv.h
More file actions
142 lines (117 loc) · 2.73 KB
/
Copy pathHashMap_priv.h
File metadata and controls
142 lines (117 loc) · 2.73 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
/*
* 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_priv_h
#define __pljava_HashMap_priv_h
#include "pljava/PgObject_priv.h"
#include "pljava/Iterator.h"
#include "pljava/HashMap.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************
* Private section of the HashMap class
*
* @author Thomas Hallgren
*****************************************************************/
struct HashKeyClass_;
typedef struct HashKeyClass_* HashKeyClass;
struct HashKeyClass_
{
struct PgObjectClass_ extendedClass;
/*
* Return the hashCode of self.
*/
uint32 (*hashCode)(HashKey self);
/*
* Return true if self is equal to other.
*/
bool (*equals)(HashKey self, HashKey other);
/*
* Create a copy of self in MemoryContext ctx.
*/
HashKey (*clone)(HashKey self, MemoryContext ctx);
};
struct HashKey_
{
HashKeyClass m_class;
};
/*
* HashKey for Oid.
*/
struct OidKey_
{
struct HashKey_ HashKey_extension;
Oid key;
};
typedef struct OidKey_* OidKey;
/*
* HashKey for an Opaque pointer, uses the pointer itself
* as the hash value.
*/
struct OpaqueKey_
{
struct HashKey_ HashKey_extension;
void* key;
};
typedef struct OpaqueKey_* OpaqueKey;
/*
* HashKey for strings.
*/
struct StringKey_
{
struct HashKey_ HashKey_extension;
/* We preserve the computed hashcode here.
*/
uint32 hash;
const char* key;
};
typedef struct StringKey_* StringKey;
/*
* HashKey for a string and an Oid.
*/
struct StringOidKey_
{
struct StringKey_ StringKey_extension;
Oid oid;
};
typedef struct StringOidKey_* StringOidKey;
/*
* Default clone method. Allocates a new instance in the given MemoryContext
* and copies the orginial HashKey using memcpy and the size stated in the
* class.
*/
extern HashKey _HashKey_clone(HashKey self, MemoryContext ctx);
/*
* Allocate a HashKeyClass for instances of a specific class.
*/
extern HashKeyClass HashKeyClass_alloc(const char* className, Size instanceSize, Finalizer finalizer);
struct HashMap_
{
struct PgObject_ PgObject_extension;
Entry* table;
uint32 tableSize;
uint32 size;
};
struct Entry_
{
struct PgObject_ PgObject_extension;
HashKey key;
void* value;
Entry next;
};
#define Entry_create(ctx) ((Entry)PgObjectClass_allocInstance(s_EntryClass, ctx))
#define HASHSLOT(self, key) (HashKey_hashCode(key) % self->tableSize)
#ifdef __cplusplus
} /* end of extern "C" declaration */
#endif
#endif