drmHashFirst(), etc.
# endif
#endif
-#define N(x) drm##x
-
#define HASH_MAGIC 0xdeadbeef
#define HASH_DEBUG 0
#define HASH_SIZE 512 /* Good for about 100 entries */
} HashTable, *HashTablePtr;
#if HASH_MAIN
-extern void *N(HashCreate)(void);
-extern int N(HashDestroy)(void *t);
-extern int N(HashLookup)(void *t, unsigned long key, unsigned long *value);
-extern int N(HashInsert)(void *t, unsigned long key, unsigned long value);
-extern int N(HashDelete)(void *t, unsigned long key);
+extern void *drmHashCreate(void);
+extern int drmHashDestroy(void *t);
+extern int drmHashLookup(void *t, unsigned long key, unsigned long *value);
+extern int drmHashInsert(void *t, unsigned long key, unsigned long value);
+extern int drmHashDelete(void *t, unsigned long key);
#endif
static unsigned long HashHash(unsigned long key)
return hash;
}
-void *N(HashCreate)(void)
+void *drmHashCreate(void)
{
HashTablePtr table;
int i;
return table;
}
-int N(HashDestroy)(void *t)
+int drmHashDestroy(void *t)
{
HashTablePtr table = (HashTablePtr)t;
HashBucketPtr bucket;
return NULL;
}
-int N(HashLookup)(void *t, unsigned long key, void **value)
+int drmHashLookup(void *t, unsigned long key, void **value)
{
HashTablePtr table = (HashTablePtr)t;
HashBucketPtr bucket;
return 0; /* Found */
}
-int N(HashInsert)(void *t, unsigned long key, void *value)
+int drmHashInsert(void *t, unsigned long key, void *value)
{
HashTablePtr table = (HashTablePtr)t;
HashBucketPtr bucket;
return 0; /* Added to table */
}
-int N(HashDelete)(void *t, unsigned long key)
+int drmHashDelete(void *t, unsigned long key)
{
HashTablePtr table = (HashTablePtr)t;
unsigned long hash;
return 0;
}
-int N(HashNext)(void *t, unsigned long *key, void **value)
+int drmHashNext(void *t, unsigned long *key, void **value)
{
HashTablePtr table = (HashTablePtr)t;
return 0;
}
-int N(HashFirst)(void *t, unsigned long *key, void **value)
+int drmHashFirst(void *t, unsigned long *key, void **value)
{
HashTablePtr table = (HashTablePtr)t;
table->p0 = 0;
table->p1 = table->buckets[0];
- return N(HashNext)(table, key, value);
+ return drmHashNext(table, key, value);
}
#if HASH_MAIN
unsigned long key, unsigned long value)
{
unsigned long retval = 0;
- int retcode = N(HashLookup)(table, key, &retval);
+ int retcode = drmHashLookup(table, key, &retval);
switch (retcode) {
case -1:
int i;
printf("\n***** 256 consecutive integers ****\n");
- table = N(HashCreate)();
- for (i = 0; i < 256; i++) N(HashInsert)(table, i, i);
+ table = drmHashCreate();
+ for (i = 0; i < 256; i++) drmHashInsert(table, i, i);
for (i = 0; i < 256; i++) check_table(table, i, i);
for (i = 256; i >= 0; i--) check_table(table, i, i);
compute_dist(table);
- N(HashDestroy)(table);
+ drmHashDestroy(table);
printf("\n***** 1024 consecutive integers ****\n");
- table = N(HashCreate)();
- for (i = 0; i < 1024; i++) N(HashInsert)(table, i, i);
+ table = drmHashCreate();
+ for (i = 0; i < 1024; i++) drmHashInsert(table, i, i);
for (i = 0; i < 1024; i++) check_table(table, i, i);
for (i = 1024; i >= 0; i--) check_table(table, i, i);
compute_dist(table);
- N(HashDestroy)(table);
+ drmHashDestroy(table);
printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
- table = N(HashCreate)();
- for (i = 0; i < 1024; i++) N(HashInsert)(table, i*4096, i);
+ table = drmHashCreate();
+ for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i);
for (i = 0; i < 1024; i++) check_table(table, i*4096, i);
for (i = 1024; i >= 0; i--) check_table(table, i*4096, i);
compute_dist(table);
- N(HashDestroy)(table);
+ drmHashDestroy(table);
printf("\n***** 1024 random integers ****\n");
- table = N(HashCreate)();
+ table = drmHashCreate();
srandom(0xbeefbeef);
- for (i = 0; i < 1024; i++) N(HashInsert)(table, random(), i);
+ for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i);
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++) check_table(table, random(), i);
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++) check_table(table, random(), i);
compute_dist(table);
- N(HashDestroy)(table);
+ drmHashDestroy(table);
printf("\n***** 5000 random integers ****\n");
- table = N(HashCreate)();
+ table = drmHashCreate();
srandom(0xbeefbeef);
- for (i = 0; i < 5000; i++) N(HashInsert)(table, random(), i);
+ for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i);
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++) check_table(table, random(), i);
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++) check_table(table, random(), i);
compute_dist(table);
- N(HashDestroy)(table);
+ drmHashDestroy(table);
return 0;
}
# endif
#endif
-#define N(x) drm##x
-
#define RANDOM_MAGIC 0xfeedbeef
#define RANDOM_DEBUG 0
} RandomState;
#if RANDOM_MAIN
-extern void *N(RandomCreate)(unsigned long seed);
-extern int N(RandomDestroy)(void *state);
-extern unsigned long N(Random)(void *state);
-extern double N(RandomDouble)(void *state);
+extern void *drmRandomCreate(unsigned long seed);
+extern int drmRandomDestroy(void *state);
+extern unsigned long drmRandom(void *state);
+extern double drmRandomDouble(void *state);
#endif
-void *N(RandomCreate)(unsigned long seed)
+void *drmRandomCreate(unsigned long seed)
{
RandomState *state;
return state;
}
-int N(RandomDestroy)(void *state)
+int drmRandomDestroy(void *state)
{
RANDOM_FREE(state);
return 0;
}
-unsigned long N(Random)(void *state)
+unsigned long drmRandom(void *state)
{
RandomState *s = (RandomState *)state;
long hi;
return s->seed;
}
-double N(RandomDouble)(void *state)
+double drmRandomDouble(void *state)
{
RandomState *s = (RandomState *)state;
- return (double)N(Random)(state)/(double)s->m;
+ return (double)drmRandom(state)/(double)s->m;
}
#if RANDOM_MAIN
unsigned long initial;
void *state;
- state = N(RandomCreate)(seed);
- initial = N(Random)(state);
+ state = drmRandomCreate(seed);
+ initial = drmRandom(state);
++count;
- while (initial != N(Random)(state)) {
+ while (initial != drmRandom(state)) {
if (!++count) break;
}
printf("With seed of %10ld, period = %10lu (0x%08lx)\n",
seed, count, count);
- N(RandomDestroy)(state);
+ drmRandomDestroy(state);
}
int main(void)
int i;
unsigned long rand;
- state = N(RandomCreate)(1);
+ state = drmRandomCreate(1);
for (i = 0; i < 10000; i++) {
- rand = N(Random)(state);
+ rand = drmRandom(state);
}
printf("After 10000 iterations: %lu (%lu expected): %s\n",
rand, state->check,
rand - state->check ? "*INCORRECT*" : "CORRECT");
- N(RandomDestroy)(state);
+ drmRandomDestroy(state);
printf("Checking periods...\n");
check_period(1);
# endif
#endif
-#define N(x) drm##x
-
#define SL_LIST_MAGIC 0xfacade00LU
#define SL_ENTRY_MAGIC 0x00fab1edLU
#define SL_FREED_MAGIC 0xdecea5edLU
} SkipList, *SkipListPtr;
#if SL_MAIN
-extern void *N(SLCreate)(void);
-extern int N(SLDestroy)(void *l);
-extern int N(SLLookup)(void *l, unsigned long key, void **value);
-extern int N(SLInsert)(void *l, unsigned long key, void *value);
-extern int N(SLDelete)(void *l, unsigned long key);
-extern int N(SLNext)(void *l, unsigned long *key, void **value);
-extern int N(SLFirst)(void *l, unsigned long *key, void **value);
-extern void N(SLDump)(void *l);
-extern int N(SLLookupNeighbors)(void *l, unsigned long key,
+extern void *drmSLCreate(void);
+extern int drmSLDestroy(void *l);
+extern int drmSLLookup(void *l, unsigned long key, void **value);
+extern int drmSLInsert(void *l, unsigned long key, void *value);
+extern int drmSLDelete(void *l, unsigned long key);
+extern int drmSLNext(void *l, unsigned long *key, void **value);
+extern int drmSLFirst(void *l, unsigned long *key, void **value);
+extern void drmSLDump(void *l);
+extern int drmSLLookupNeighbors(void *l, unsigned long key,
unsigned long *prev_key, void **prev_value,
unsigned long *next_key, void **next_value);
#endif
return level;
}
-void *N(SLCreate)(void)
+void *drmSLCreate(void)
{
SkipListPtr list;
int i;
return list;
}
-int N(SLDestroy)(void *l)
+int drmSLDestroy(void *l)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
return entry->forward[0];
}
-int N(SLInsert)(void *l, unsigned long key, void *value)
+int drmSLInsert(void *l, unsigned long key, void *value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
return 0; /* Added to table */
}
-int N(SLDelete)(void *l, unsigned long key)
+int drmSLDelete(void *l, unsigned long key)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr update[SL_MAX_LEVEL + 1];
return 0;
}
-int N(SLLookup)(void *l, unsigned long key, void **value)
+int drmSLLookup(void *l, unsigned long key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr update[SL_MAX_LEVEL + 1];
return -1;
}
-int N(SLLookupNeighbors)(void *l, unsigned long key,
+int drmSLLookupNeighbors(void *l, unsigned long key,
unsigned long *prev_key, void **prev_value,
unsigned long *next_key, void **next_value)
{
return retcode;
}
-int N(SLNext)(void *l, unsigned long *key, void **value)
+int drmSLNext(void *l, unsigned long *key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
return 0;
}
-int N(SLFirst)(void *l, unsigned long *key, void **value)
+int drmSLFirst(void *l, unsigned long *key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */
list->p0 = list->head->forward[0];
- return N(SLNext)(list, key, value);
+ return drmSLNext(list, key, value);
}
/* Dump internal data structures for debugging. */
-void N(SLDump)(void *l)
+void drmSLDump(void *l)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
unsigned long key;
void *value;
- if (N(SLFirst)(list, &key, &value)) {
+ if (drmSLFirst(list, &key, &value)) {
do {
printf("key = %5lu, value = %p\n", key, value);
- } while (N(SLNext)(list, &key, &value));
+ } while (drmSLNext(list, &key, &value));
}
}
SL_RANDOM_INIT(12345);
- list = N(SLCreate)();
+ list = drmSLCreate();
for (i = 0; i < size; i++) {
keys[i] = SL_RANDOM;
- N(SLInsert)(list, keys[i], NULL);
+ drmSLInsert(list, keys[i], NULL);
}
previous = 0;
- if (N(SLFirst)(list, &key, &value)) {
+ if (drmSLFirst(list, &key, &value)) {
do {
if (key <= previous) {
printf( "%lu !< %lu\n", previous, key);
}
previous = key;
- } while (N(SLNext)(list, &key, &value));
+ } while (drmSLNext(list, &key, &value));
}
gettimeofday(&start, NULL);
for (j = 0; j < iter; j++) {
for (i = 0; i < size; i++) {
- if (N(SLLookup)(list, keys[i], &value))
+ if (drmSLLookup(list, keys[i], &value))
printf("Error %lu %d\n", keys[i], i);
}
}
printf("%0.2f microseconds for list length %d\n", usec, size);
- N(SLDestroy)(list);
+ drmSLDestroy(list);
return usec;
}
SkipListPtr list;
double usec, usec2, usec3, usec4;
- list = N(SLCreate)();
+ list = drmSLCreate();
printf( "list at %p\n", list);
print(list);
printf("\n==============================\n\n");
- N(SLInsert)(list, 123, NULL);
- N(SLInsert)(list, 213, NULL);
- N(SLInsert)(list, 50, NULL);
+ drmSLInsert(list, 123, NULL);
+ drmSLInsert(list, 213, NULL);
+ drmSLInsert(list, 50, NULL);
print(list);
printf("\n==============================\n\n");
print_neighbors(list, 256);
printf("\n==============================\n\n");
- N(SLDelete)(list, 50);
+ drmSLDelete(list, 50);
print(list);
printf("\n==============================\n\n");
- N(SLDump)(list);
- N(SLDestroy)(list);
+ drmSLDump(list);
+ drmSLDestroy(list);
printf("\n==============================\n\n");
usec = do_time(100, 10000);