# HG changeset patch # User Me@portablequad # Date 1329011751 28800 # Node ID 5b89d57e5d10a6b10a47ccbe89d04ee7395fcdb9 # Parent c934e7d8ab55992e5ecd90062591ebae62009aaa added .brch__VMS__malloc_brch which has purpose of the brch diff -r c934e7d8ab55 -r 5b89d57e5d10 .brch__VMS__malloc_brch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.brch__VMS__malloc_brch Sat Feb 11 17:55:51 2012 -0800 @@ -0,0 +1,4 @@ +This branch is for the project structure defined Jan 2012.. the #includes reflect this directory structure. + +More importantly, the MC_shared version of VMS requires a separat malloc implemeted by VMS code.. so this branch has modified the library to use the VMS-specific malloc. + diff -r c934e7d8ab55 -r 5b89d57e5d10 .hgeol --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgeol Sat Feb 11 17:55:51 2012 -0800 @@ -0,0 +1,14 @@ + +[patterns] +**.py = native +**.txt = native +**.c = native +**.h = native +**.cpp = native +**.java = native +**.class = bin +**.jar = bin +**.sh = native +**.pl = native +**.jpg = bin +**.gif = bin diff -r c934e7d8ab55 -r 5b89d57e5d10 MurmurHash2.c --- a/MurmurHash2.c Thu Feb 09 15:51:22 2012 +0100 +++ b/MurmurHash2.c Sat Feb 11 17:55:51 2012 -0800 @@ -1,64 +1,69 @@ -//----------------------------------------------------------------------------- -// MurmurHash2, by Austin Appleby - -// Note - This code makes a few assumptions about how your machine behaves - - -// 1. We can read a 4-byte value from any address without crashing -// 2. sizeof(int) == 4 - -// And it has a few limitations - - -// 1. It will not work incrementally. -// 2. It will not produce the same results on little-endian and big-endian -// machines. - -unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) -{ - // 'm' and 'r' are mixing constants generated offline. - // They're not really 'magic', they just happen to work well. - - const unsigned int m = 0x5bd1e995; - const int r = 24; - - // Initialize the hash to a 'random' value - - unsigned int h = seed ^ len; - - // Mix 4 bytes at a time into the hash - - const unsigned char * data = (const unsigned char *)key; - - while(len >= 4) - { - unsigned int k = *(unsigned int *)data; - - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; - - data += 4; - len -= 4; - } - - // Handle the last few bytes of the input array - - switch(len) - { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; - case 1: h ^= data[0]; - h *= m; - }; - - // Do a few final mixes of the hash to ensure the last few - // bytes are well-incorporated. - - h ^= h >> 13; - h *= m; - h ^= h >> 15; - - return h; -} + +/*This file is sample code pulled off the web -- NOT part of the compiled code + * make sure it doesn't get included in makefile 'cause it doesn't compile + */ + +//----------------------------------------------------------------------------- +// MurmurHash2, by Austin Appleby + +// Note - This code makes a few assumptions about how your machine behaves - + +// 1. We can read a 4-byte value from any address without crashing +// 2. sizeof(int) == 4 + +// And it has a few limitations - + +// 1. It will not work incrementally. +// 2. It will not produce the same results on little-endian and big-endian +// machines. + +unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) +{ + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + + const unsigned int m = 0x5bd1e995; + const int r = 24; + + // Initialize the hash to a 'random' value + + unsigned int h = seed ^ len; + + // Mix 4 bytes at a time into the hash + + const unsigned char * data = (const unsigned char *)key; + + while(len >= 4) + { + unsigned int k = *(unsigned int *)data; + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + + data += 4; + len -= 4; + } + + // Handle the last few bytes of the input array + + switch(len) + { + case 3: h ^= data[2] << 16; + case 2: h ^= data[1] << 8; + case 1: h ^= data[0]; + h *= m; + }; + + // Do a few final mixes of the hash to ensure the last few + // bytes are well-incorporated. + + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} diff -r c934e7d8ab55 -r 5b89d57e5d10 PrivateHash.c --- a/PrivateHash.c Thu Feb 09 15:51:22 2012 +0100 +++ b/PrivateHash.c Sat Feb 11 17:55:51 2012 -0800 @@ -1,249 +1,242 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * - * Author: seanhalle@yahoo.com - */ - - -#include -#include -#include -#include - -#include "PrivateHash.h" -#include "../vmalloc.h" - - - HashTable * -makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) - { HashTable * retTable; - retTable = VMS__malloc( sizeof( HashTable ) ); - - retTable->freeEntryContentFn = freeFn; - - retTable->entries = VMS__malloc( numHashSlots * sizeof(HashEntry *) ); - retTable->numEntries = 0; - retTable->tableSz = numHashSlots; - - nullOutTablesArray( retTable ); - - return retTable; - } - - void -doubleTableSize( HashTable *table ) - { int i, oldTableSz, newTableSz; - HashEntry *entry, *nextEntry, **oldEntries, **newEntries; - - oldTableSz = table->tableSz; - oldEntries = table->entries; - - newTableSz = 2 * oldTableSz + 1; - newEntries = VMS__malloc( newTableSz * sizeof(HashEntry *) ); - - table->tableSz = newTableSz; - table->entries = newEntries; - table->numEntries = 0; //about to add them all back! - - // move all the entries from old to new - for( i=0; i < oldTableSz; i++ ) - { if( oldEntries[i] != NULL ) - { entry = oldEntries[i]; - while( entry != NULL ) - { nextEntry = entry->next; - entry->next = NULL; - putEntryIntoTable( entry, table ); //does not allocate anything - entry = nextEntry; - } - } - } - } - -void -nullOutTablesArray( HashTable *table ) - { int i, tableSz; - tableSz = table->tableSz; - HashEntry ** entries = table->entries; - for( i = 0; i < tableSz; i++ ) - entries[ i ] = NULL; - } - -unsigned int -hashThisKey( char* s, int hashSz ) - { unsigned int h = 0; - unsigned int i; - hashkey_t* key = (hashkey_t*)s; - - for(i=0 ; ihashable[i] + h*31; - return h % hashSz; - } - -/*Need this to be separated out, for use in both getParam and putParam - */ -HashEntry * -getEntryFromTable( char *key, HashTable * table ) - { unsigned int - hashIndex = hashThisKey( key, table->tableSz ); - HashEntry* - hashEntry = table->entries[ hashIndex ]; - for( ; hashEntry != NULL; hashEntry = hashEntry->next ) - { - if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) - return hashEntry; - } - return NULL; - } - -void * -getValueFromTable( char *key, HashTable * table ) - { HashEntry *entry; - entry = getEntryFromTable( key, table ); - if( entry == NULL ) return NULL; - - return entry->content; - } - - -/*If key already has a value, clobber the old one and replace it - */ - int -addValueIntoTable( char* key, void *content, HashTable *table ) - { unsigned int hashIdx; - HashEntry* hashEntry; - - hashEntry = getEntryFromTable( key, table ); - if( hashEntry == NULL ) - { hashIdx = hashThisKey( key, table->tableSz ); - hashEntry = (HashEntry*) VMS__malloc( sizeof( HashEntry ) ); - if( hashEntry == NULL ) return 0; - hashEntry->key = VMS__malloc( sizeof(hashkey_t) ); - if( hashEntry->key == NULL ) return 0; - memcpy( hashEntry->key, key, sizeof(hashkey_t) ); - hashEntry->next = (table->entries)[hashIdx]; - (table->entries)[hashIdx] = hashEntry; - table->numEntries += 1; - if( table->tableSz < table->numEntries ) doubleTableSize( table ); - } - else - { (*(table->freeEntryContentFn))( hashEntry->content ); - } - hashEntry->content = content; - return 1; - } - - int -putEntryIntoTable( HashEntry *entry, HashTable *table ) - { unsigned int hashIdx; - HashEntry* testEntry; - - testEntry = getEntryFromTable( entry->key, table ); - if( testEntry == NULL ) - { hashIdx = hashThisKey( entry->key, table->tableSz ); - entry->next = (table->entries)[hashIdx]; - (table->entries)[hashIdx] = entry; - table->numEntries += 1; - if( table->tableSz < table->numEntries ) doubleTableSize( table ); - } - else - { (*(table->freeEntryContentFn))( testEntry->content ); - //being lazy -- will create bug in code that relies on having ptr to - // elem given to insert into table! - testEntry->content = entry->content; - entry->content = NULL; - freeHashEntryButNotContent( entry ); - } - return 1; - } - -/*Better version - */ - void -untested_putEntryIntoTable( HashEntry *entry, HashTable * table ) - { HashEntry *testEntry, *prevEntry = NULL; - unsigned int - hashIndex = hashThisKey( entry->key, table->tableSz ); - - testEntry = table->entries[ hashIndex ]; - for( ; testEntry != NULL; testEntry = testEntry->next ) - { if( memcmp( testEntry->key, entry->key, sizeof(hashkey_t)) == 0 ) - { if( prevEntry == NULL ) - { table->entries[hashIndex] = entry; - entry->next = testEntry->next; - } - else - { prevEntry->next = entry; - entry->next = testEntry->next; - } - freeHashEntryUsing( testEntry, table ); //frees content too! - return; - } - } - //wasn't found, so insert - entry->next = table->entries[hashIndex]; - table->entries[hashIndex] = entry; - } - - - - bool8 -deleteEntryFromTable( char *key, HashTable *table ) - { HashEntry *hashEntry; - HashEntry **addrOfHashEntryPtr; - unsigned int hashIndex; - - hashIndex = hashThisKey( key, table->tableSz ); - addrOfHashEntryPtr = &( table->entries[ hashIndex ] ); - hashEntry = *addrOfHashEntryPtr; - while( hashEntry != NULL ) - { if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) - { - *addrOfHashEntryPtr = hashEntry->next; - //TODO: Free the contents of entry? - freeHashEntryButNotContent( hashEntry ); - table->numEntries -= 1; - return TRUE; - } - addrOfHashEntryPtr = &( hashEntry->next ); - hashEntry = *addrOfHashEntryPtr; - } - return FALSE; - } - -void -freeHashTable( HashTable *table ) - { int i; - HashEntry *hashEntry, *temp, **entries; - - entries = table->entries; - for( i=0; i < table->tableSz; i++ ) - { if( entries[i] != NULL ) - { hashEntry = entries[i]; - while( hashEntry != NULL ) - { - temp = hashEntry->next; - freeHashEntryUsing( hashEntry, table ); - hashEntry = temp; - } - } - } - } - -void -freeHashEntryUsing( HashEntry *entry, HashTable *table ) - { - if( entry->content != NULL ) - (*(table->freeEntryContentFn))( entry->content ); - VMS__free( entry->key ); //was VMS__malloc'd above, so free it - VMS__free( entry ); - } - -void -freeHashEntryButNotContent( HashEntry *entry ) - { - VMS__free( entry->key ); //was VMS__malloc'd above, so free it - VMS__free( entry ); - } - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * + * Author: seanhalle@yahoo.com + */ + +#include "PrivateHash.h" + + + HashTable * +makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) + { HashTable * retTable; + retTable = VMS__malloc( sizeof( HashTable ) ); + + retTable->freeEntryContentFn = freeFn; + + retTable->entries = VMS__malloc( numHashSlots * sizeof(HashEntry *) ); + retTable->numEntries = 0; + retTable->tableSz = numHashSlots; + + nullOutTablesArray( retTable ); + + return retTable; + } + + void +doubleTableSize( HashTable *table ) + { int i, oldTableSz, newTableSz; + HashEntry *entry, *nextEntry, **oldEntries, **newEntries; + + oldTableSz = table->tableSz; + oldEntries = table->entries; + + newTableSz = 2 * oldTableSz + 1; + newEntries = VMS__malloc( newTableSz * sizeof(HashEntry *) ); + + table->tableSz = newTableSz; + table->entries = newEntries; + table->numEntries = 0; //about to add them all back! + + // move all the entries from old to new + for( i=0; i < oldTableSz; i++ ) + { if( oldEntries[i] != NULL ) + { entry = oldEntries[i]; + while( entry != NULL ) + { nextEntry = entry->next; + entry->next = NULL; + putEntryIntoTable( entry, table ); //does not allocate anything + entry = nextEntry; + } + } + } + } + +void +nullOutTablesArray( HashTable *table ) + { int i, tableSz; + tableSz = table->tableSz; + HashEntry ** entries = table->entries; + for( i = 0; i < tableSz; i++ ) + entries[ i ] = NULL; + } + +unsigned int +hashThisKey( char* s, int hashSz ) + { unsigned int h = 0; + unsigned int i; + hashkey_t* key = (hashkey_t*)s; + + for(i=0 ; ihashable[i] + h*31; + return h % hashSz; + } + +/*Need this to be separated out, for use in both getParam and putParam + */ +HashEntry * +getEntryFromTable( char *key, HashTable * table ) + { unsigned int + hashIndex = hashThisKey( key, table->tableSz ); + HashEntry* + hashEntry = table->entries[ hashIndex ]; + for( ; hashEntry != NULL; hashEntry = hashEntry->next ) + { + if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) + return hashEntry; + } + return NULL; + } + +void * +getValueFromTable( char *key, HashTable * table ) + { HashEntry *entry; + entry = getEntryFromTable( key, table ); + if( entry == NULL ) return NULL; + + return entry->content; + } + + +/*If key already has a value, clobber the old one and replace it + */ + int +addValueIntoTable( char* key, void *content, HashTable *table ) + { unsigned int hashIdx; + HashEntry* hashEntry; + + hashEntry = getEntryFromTable( key, table ); + if( hashEntry == NULL ) + { hashIdx = hashThisKey( key, table->tableSz ); + hashEntry = (HashEntry*) VMS__malloc( sizeof( HashEntry ) ); + if( hashEntry == NULL ) return 0; + hashEntry->key = VMS__malloc( sizeof(hashkey_t) ); + if( hashEntry->key == NULL ) return 0; + memcpy( hashEntry->key, key, sizeof(hashkey_t) ); + hashEntry->next = (table->entries)[hashIdx]; + (table->entries)[hashIdx] = hashEntry; + table->numEntries += 1; + if( table->tableSz < table->numEntries ) doubleTableSize( table ); + } + else + { (*(table->freeEntryContentFn))( hashEntry->content ); + } + hashEntry->content = content; + return 1; + } + + int +putEntryIntoTable( HashEntry *entry, HashTable *table ) + { unsigned int hashIdx; + HashEntry* testEntry; + + testEntry = getEntryFromTable( entry->key, table ); + if( testEntry == NULL ) + { hashIdx = hashThisKey( entry->key, table->tableSz ); + entry->next = (table->entries)[hashIdx]; + (table->entries)[hashIdx] = entry; + table->numEntries += 1; + if( table->tableSz < table->numEntries ) doubleTableSize( table ); + } + else + { (*(table->freeEntryContentFn))( testEntry->content ); + //being lazy -- will create bug in code that relies on having ptr to + // elem given to insert into table! + testEntry->content = entry->content; + entry->content = NULL; + freeHashEntryButNotContent( entry ); + } + return 1; + } + +/*Better version + */ + void +untested_putEntryIntoTable( HashEntry *entry, HashTable * table ) + { HashEntry *testEntry, *prevEntry = NULL; + unsigned int + hashIndex = hashThisKey( entry->key, table->tableSz ); + + testEntry = table->entries[ hashIndex ]; + for( ; testEntry != NULL; testEntry = testEntry->next ) + { if( memcmp( testEntry->key, entry->key, sizeof(hashkey_t)) == 0 ) + { if( prevEntry == NULL ) + { table->entries[hashIndex] = entry; + entry->next = testEntry->next; + } + else + { prevEntry->next = entry; + entry->next = testEntry->next; + } + freeHashEntryUsing( testEntry, table ); //frees content too! + return; + } + } + //wasn't found, so insert + entry->next = table->entries[hashIndex]; + table->entries[hashIndex] = entry; + } + + + + bool8 +deleteEntryFromTable( char *key, HashTable *table ) + { HashEntry *hashEntry; + HashEntry **addrOfHashEntryPtr; + unsigned int hashIndex; + + hashIndex = hashThisKey( key, table->tableSz ); + addrOfHashEntryPtr = &( table->entries[ hashIndex ] ); + hashEntry = *addrOfHashEntryPtr; + while( hashEntry != NULL ) + { if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) + { + *addrOfHashEntryPtr = hashEntry->next; + //TODO: Free the contents of entry? + freeHashEntryButNotContent( hashEntry ); + table->numEntries -= 1; + return TRUE; + } + addrOfHashEntryPtr = &( hashEntry->next ); + hashEntry = *addrOfHashEntryPtr; + } + return FALSE; + } + +void +freeHashTable( HashTable *table ) + { int i; + HashEntry *hashEntry, *temp, **entries; + + entries = table->entries; + for( i=0; i < table->tableSz; i++ ) + { if( entries[i] != NULL ) + { hashEntry = entries[i]; + while( hashEntry != NULL ) + { + temp = hashEntry->next; + freeHashEntryUsing( hashEntry, table ); + hashEntry = temp; + } + } + } + } + +void +freeHashEntryUsing( HashEntry *entry, HashTable *table ) + { + if( entry->content != NULL ) + (*(table->freeEntryContentFn))( entry->content ); + VMS__free( entry->key ); //was VMS__malloc'd above, so free it + VMS__free( entry ); + } + +void +freeHashEntryButNotContent( HashEntry *entry ) + { + VMS__free( entry->key ); //was VMS__malloc'd above, so free it + VMS__free( entry ); + } + diff -r c934e7d8ab55 -r 5b89d57e5d10 PrivateHash.h --- a/PrivateHash.h Thu Feb 09 15:51:22 2012 +0100 +++ b/PrivateHash.h Sat Feb 11 17:55:51 2012 -0800 @@ -1,70 +1,76 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - */ - -#ifndef _PRIVATE_HASH_H -#define _PRIVATE_HASH_H - -#include "../../VMS_Implementations/VMS_impl/VMS_primitive_data_types.h" - -#define TRUE 1 -#define FALSE 0 - -union hashkey_t{ - char hashable[8]; - int parts[2]; -}; - -typedef union hashkey_t hashkey_t; - -#define DEFAULT_HASHSIZE 1 << 10 - -typedef struct _HashEntry HashEntry; - -struct _HashEntry - { - char *key; - void *content; - HashEntry *next; - }; - -typedef void (*FreeEntryContentFnPtr) ( void * ); - -typedef struct - { int tableSz; - int numEntries; - HashEntry* *entries; - FreeEntryContentFnPtr freeEntryContentFn; - } -HashTable; - - -//=========================================================================== -// Public functions -HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); - -int putEntryIntoTable( HashEntry *entry, HashTable *table); -int addValueIntoTable( char* key, void *value, HashTable *table); -HashEntry *getEntryFromTable( char *key, HashTable *table ); -void *getValueFromTable( char *key, HashTable *table ); - -bool8 deleteEntryFromTable( char *key, HashTable *table ); -bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); -bool8 deleteEntrysValueInTable( char *key, HashTable *table ); -bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); -void freeHashTable( HashTable *table ); -//char *paramBagToString( ParamBag * bag ) - -//=========================================================================== -// Internal functions -void freeHashEntryUsing( HashEntry *entry, HashTable *table ); -unsigned int hashThisKey( char *s, int hashSz ); -void nullOutTablesArray( HashTable *table ); -void doubleTableSize( HashTable *table ); -void freeHashEntryButNotContent( HashEntry *entry ); - -#endif /* _PRIVATE_HASH_H */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + */ + +#ifndef _PRIVATE_HASH_H +#define _PRIVATE_HASH_H + +#include +#include +#include +#include + +#include "../../VMS_Implementations/VMS_impl/VMS_primitive_data_types.h" +#include "../../VMS_Implementations/VMS_impl/vmalloc.h" + +#define TRUE 1 +#define FALSE 0 + +union hashkey_t{ + char hashable[8]; + int parts[2]; +}; + +typedef union hashkey_t hashkey_t; + +#define DEFAULT_HASHSIZE 1 << 10 + +typedef struct _HashEntry HashEntry; + +struct _HashEntry + { + char *key; + void *content; + HashEntry *next; + }; + +typedef void (*FreeEntryContentFnPtr) ( void * ); + +typedef struct + { int tableSz; + int numEntries; + HashEntry* *entries; + FreeEntryContentFnPtr freeEntryContentFn; + } +HashTable; + + +//=========================================================================== +// Public functions +HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); + +int putEntryIntoTable( HashEntry *entry, HashTable *table); +int addValueIntoTable( char* key, void *value, HashTable *table); +HashEntry *getEntryFromTable( char *key, HashTable *table ); +void *getValueFromTable( char *key, HashTable *table ); + +bool8 deleteEntryFromTable( char *key, HashTable *table ); +bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); +bool8 deleteEntrysValueInTable( char *key, HashTable *table ); +bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); +void freeHashTable( HashTable *table ); +//char *paramBagToString( ParamBag * bag ) + +//=========================================================================== +// Internal functions +void freeHashEntryUsing( HashEntry *entry, HashTable *table ); +unsigned int hashThisKey( char *s, int hashSz ); +void nullOutTablesArray( HashTable *table ); +void doubleTableSize( HashTable *table ); +void freeHashEntryButNotContent( HashEntry *entry ); + +#endif /* _PRIVATE_HASH_H */ +