4 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
7 Desc: Demo of new OOP system - General hashing definitions.
12 # include <exec/types.h>
19 #define HashMask(ht) ( (ht)->HashMask )
20 #define HashSize(ht) ( HashMask(ht) + 1 )
21 #define MAX_HASH_CHARS 50
23 /* Types of hashtables. Can hash integers or strings */
30 /* Default Bucket struct. The userdefined bucket must
31 ** have this structure defined at the top
35 /* Each entry in the hashtable is a linked list of buckets */
37 /* The ID used to lookup hashed items */
44 /* Pointer hash array itself */
45 struct Bucket
**Table
;
47 /* function for looking up the correct bucket for a supplied ID.
48 ** Returns NULL if none found.
49 ** Implementations is dependant on whether it's a HT_STRING
50 ** or HT_INTEGER hash table. Do not try to look up a string id
51 ** in an integer hash table or vice versa.
53 struct Bucket
* (*Lookup
)(struct HashTable
*ht
, IPTR id
, struct IntOOPBase
*OOPBase
);
55 /* Calcultes an offset into the hashtable according to the ID.
56 ** Implementations dependes whether hashtable is of type
57 ** HT_STRING or HT_INTEGER. Do not try to hash a string id
58 ** in an integer hash table or vice versa.
61 ULONG (*CalcHash
)(struct HashTable
*ht
, IPTR id
);
63 /* Mask used by CalcHash() */
66 /* Hash table type: HT_STRING or HT_INTEGER */
67 UBYTE Type
; /* String or integer */
72 /* Create a new empty hashtable. Type can be HT_STRING or HT_INTEGER */
73 struct HashTable
*NewHash(ULONG entries
, UBYTE type
, struct IntOOPBase
*OOPBase
);
75 /* Free a hashtable previously allocated with NewHash().
76 You must supply a function for freeing evt. buckets in the table.
78 VOID
FreeHash(struct HashTable
*ht
, VOID (*freebucket
)(), struct IntOOPBase
*OOPBase
);
80 /* The implemntations of hashtable->HashLookup() */
81 struct Bucket
*HashLookupULONG(struct HashTable
*ht
, IPTR id
, struct IntOOPBase
*OOPBase
);
82 struct Bucket
*HashLookupUUID(struct HashTable
*ht
, IPTR id
, struct IntOOPBase
*OOPBase
);
83 struct Bucket
*HashLookupStr(struct HashTable
*ht
, IPTR id
, struct IntOOPBase
*OOPBase
);
85 /* Copies all the buckets of one hashtable into an other one.
86 You must supply a function to copy the buckets.
87 The user-suppplied copybucket() will get a parameter to
88 the bucket as first parameter, and a pointer to the user
89 supplied data as second parameter
92 BOOL
CopyHash(struct HashTable
*dest_ht
93 ,struct HashTable
*src_ht
94 ,struct Bucket
* (*copybucket
)()
96 ,struct IntOOPBase
*OOPBase
);
98 /* Inserts a bucket into the hashtable, according to it's ID */
99 VOID
InsertBucket(struct HashTable
*ht
, struct Bucket
*b
, struct IntOOPBase
*OOPBase
);
101 /* Removes a bucket from a hashtable */
102 VOID
RemoveBucket(struct HashTable
*ht
, struct Bucket
*b
);
104 /* The implemntations of hashtable->CalcHash() */
105 ULONG
CalcHashStr(struct HashTable
*ht
, IPTR id
);
106 ULONG
CalcHashULONG(struct HashTable
*ht
, IPTR id
);
107 ULONG
CalcHashUUID(struct HashTable
*ht
, IPTR id
);
109 VOID
print_table(struct HashTable
*ht
, struct IntOOPBase
*OOPBase
);