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
|
#ifndef __PROPERTY_TABLE_H
#define __PROPERTY_TABLE_H
//*****************************************************************************
//
// property_table.h
//
// A little idea I thought up, mainly for quick lookup of elements by vnum.
//
// Exactly like a hashtable, except the <key> component of some element is
// built into the element itself, and defined by a function that is passed
// in when the propery table is created. Currently, the property_table only
// allows one item per property value to be stored, but later on down the
// road we will expand this so that the table will collect -sets- of items
// with a given property.
//
// the main purpose for this table is to store obj/mob/script/etc prototypes,
// as well as rooms in the game.
//
//*****************************************************************************
typedef struct property_table PROPERTY_TABLE;
typedef struct property_table_iterator PROPERTY_TABLE_ITERATOR;
//
// Create a new property table with the specified number of buckets
// (more buckets = faster lookup, but more memory). The key function must
// be a function that returns a positive integer (no upper bound)
//
PROPERTY_TABLE *newPropertyTable(void *key_function, int buckets);
//
// Delete the property table, but not the elements housed within it.
//
void deletePropertyTable(PROPERTY_TABLE *table);
//
// Put an element in the table. Its key is determined by the
// function we have already passed in upon creating this table.
//
void propertyTablePut(PROPERTY_TABLE *table, void *elem);
//
// Remove and return the value assocciated with this key and our
// key-function. Return NULL if nothing exists.
//
void *propertyTableRemove(PROPERTY_TABLE *table, int key);
//
// Return the value assocciated with the key and our key-function.
// return NULL if nothing exists
//
void *propertyTableGet(PROPERTY_TABLE *table, int key);
//
// Return true if a value with the specified key exists
//
bool propertyTableIn(PROPERTY_TABLE *table, int key);
//*****************************************************************************
//
// property table iterator
//
// we may sometimes want to iterate across all of the elements in a table.
// this lets us do so.
//
//*****************************************************************************
//
// Create an iterator to go over the table
//
PROPERTY_TABLE_ITERATOR *newPropertyTableIterator(PROPERTY_TABLE *T);
//
// Delete the iterator (but not the contents)
//
void deletePropertyTableIterator(PROPERTY_TABLE_ITERATOR *I);
//
// Point the iterator back at the start of the table
//
void propertyTableIteratorReset(PROPERTY_TABLE_ITERATOR *I);
//
// Skip to the next element. Return the next element
// if one exists, and NULL otherwise.
//
void *propertyTableIteratorNext(PROPERTY_TABLE_ITERATOR *I);
//
// return a pointer to the current element
//
void *propertyTableIteratorCurrent(PROPERTY_TABLE_ITERATOR *I);
#endif // __PROPERTY_TABLE_H
|