Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
changeset 20:89d35be7a31e
deprecated default brch
| author | Me@portablequad |
|---|---|
| date | Mon, 13 Feb 2012 13:11:46 -0800 |
| parents | 093cad17d992 |
| children | |
| files | .brch__default .hgignore PrivateHash.c PrivateHash.h __brch__DEPRECATED_README |
| diffstat | 5 files changed, 8 insertions(+), 320 deletions(-) [+] |
line diff
1.1 --- a/.brch__default Sat Feb 11 18:00:56 2012 -0800 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,1 +0,0 @@ 1.4 -The default branch is for use with normal C code. Other branches specialize the library for use with VMS.. they may need VMS header files, and the working directory may be located at various different positions relative to the VMS implementation. 1.5 \ No newline at end of file
2.1 --- a/.hgignore Sat Feb 11 18:00:56 2012 -0800 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,3 +0,0 @@ 2.4 -syntax: glob 2.5 - 2.6 -*.o
3.1 --- a/PrivateHash.c Sat Feb 11 18:00:56 2012 -0800 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,242 +0,0 @@ 3.4 -/* 3.5 - * Copyright 2009 OpenSourceStewardshipFoundation.org 3.6 - * Licensed under GNU General Public License version 2 3.7 - * 3.8 - * 3.9 - * Author: seanhalle@yahoo.com 3.10 - */ 3.11 - 3.12 -#include "PrivateHash.h" 3.13 - 3.14 - 3.15 - HashTable * 3.16 -makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) 3.17 - { HashTable * retTable; 3.18 - retTable = malloc( sizeof( HashTable ) ); 3.19 - 3.20 - retTable->freeEntryContentFn = freeFn; 3.21 - 3.22 - retTable->entries = malloc( numHashSlots * sizeof(HashEntry *) ); 3.23 - retTable->numEntries = 0; 3.24 - retTable->tableSz = numHashSlots; 3.25 - 3.26 - nullOutTablesArray( retTable ); 3.27 - 3.28 - return retTable; 3.29 - } 3.30 - 3.31 - void 3.32 -doubleTableSize( HashTable *table ) 3.33 - { int i, oldTableSz, newTableSz; 3.34 - HashEntry *entry, *nextEntry, **oldEntries, **newEntries; 3.35 - 3.36 - oldTableSz = table->tableSz; 3.37 - oldEntries = table->entries; 3.38 - 3.39 - newTableSz = 2 * oldTableSz + 1; 3.40 - newEntries = malloc( newTableSz * sizeof(HashEntry *) ); 3.41 - 3.42 - table->tableSz = newTableSz; 3.43 - table->entries = newEntries; 3.44 - table->numEntries = 0; //about to add them all back! 3.45 - 3.46 - // move all the entries from old to new 3.47 - for( i=0; i < oldTableSz; i++ ) 3.48 - { if( oldEntries[i] != NULL ) 3.49 - { entry = oldEntries[i]; 3.50 - while( entry != NULL ) 3.51 - { nextEntry = entry->next; 3.52 - entry->next = NULL; 3.53 - putEntryIntoTable( entry, table ); //does not allocate anything 3.54 - entry = nextEntry; 3.55 - } 3.56 - } 3.57 - } 3.58 - } 3.59 - 3.60 -void 3.61 -nullOutTablesArray( HashTable *table ) 3.62 - { int i, tableSz; 3.63 - tableSz = table->tableSz; 3.64 - HashEntry ** entries = table->entries; 3.65 - for( i = 0; i < tableSz; i++ ) 3.66 - entries[ i ] = NULL; 3.67 - } 3.68 - 3.69 -unsigned int 3.70 -hashThisKey( char* s, int hashSz ) 3.71 - { unsigned int h = 0; 3.72 - unsigned int i; 3.73 - hashkey_t* key = (hashkey_t*)s; 3.74 - 3.75 - for(i=0 ; i<sizeof(hashkey_t); i++ ) 3.76 - h = key->hashable[i] + h*31; 3.77 - return h % hashSz; 3.78 - } 3.79 - 3.80 -/*Need this to be separated out, for use in both getParam and putParam 3.81 - */ 3.82 -HashEntry * 3.83 -getEntryFromTable( char *key, HashTable * table ) 3.84 - { unsigned int 3.85 - hashIndex = hashThisKey( key, table->tableSz ); 3.86 - HashEntry* 3.87 - hashEntry = table->entries[ hashIndex ]; 3.88 - for( ; hashEntry != NULL; hashEntry = hashEntry->next ) 3.89 - { 3.90 - if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) 3.91 - return hashEntry; 3.92 - } 3.93 - return NULL; 3.94 - } 3.95 - 3.96 -void * 3.97 -getValueFromTable( char *key, HashTable * table ) 3.98 - { HashEntry *entry; 3.99 - entry = getEntryFromTable( key, table ); 3.100 - if( entry == NULL ) return NULL; 3.101 - 3.102 - return entry->content; 3.103 - } 3.104 - 3.105 - 3.106 -/*If key already has a value, clobber the old one and replace it 3.107 - */ 3.108 - int 3.109 -addValueIntoTable( char* key, void *content, HashTable *table ) 3.110 - { unsigned int hashIdx; 3.111 - HashEntry* hashEntry; 3.112 - 3.113 - hashEntry = getEntryFromTable( key, table ); 3.114 - if( hashEntry == NULL ) 3.115 - { hashIdx = hashThisKey( key, table->tableSz ); 3.116 - hashEntry = (HashEntry*) malloc( sizeof( HashEntry ) ); 3.117 - if( hashEntry == NULL ) return 0; 3.118 - hashEntry->key = malloc( sizeof(hashkey_t) ); 3.119 - if( hashEntry->key == NULL ) return 0; 3.120 - memcpy( hashEntry->key, key, sizeof(hashkey_t) ); 3.121 - hashEntry->next = (table->entries)[hashIdx]; 3.122 - (table->entries)[hashIdx] = hashEntry; 3.123 - table->numEntries += 1; 3.124 - if( table->tableSz < table->numEntries ) doubleTableSize( table ); 3.125 - } 3.126 - else 3.127 - { (*(table->freeEntryContentFn))( hashEntry->content ); 3.128 - } 3.129 - hashEntry->content = content; 3.130 - return 1; 3.131 - } 3.132 - 3.133 - int 3.134 -putEntryIntoTable( HashEntry *entry, HashTable *table ) 3.135 - { unsigned int hashIdx; 3.136 - HashEntry* testEntry; 3.137 - 3.138 - testEntry = getEntryFromTable( entry->key, table ); 3.139 - if( testEntry == NULL ) 3.140 - { hashIdx = hashThisKey( entry->key, table->tableSz ); 3.141 - entry->next = (table->entries)[hashIdx]; 3.142 - (table->entries)[hashIdx] = entry; 3.143 - table->numEntries += 1; 3.144 - if( table->tableSz < table->numEntries ) doubleTableSize( table ); 3.145 - } 3.146 - else 3.147 - { (*(table->freeEntryContentFn))( testEntry->content ); 3.148 - //being lazy -- will create bug in code that relies on having ptr to 3.149 - // elem given to insert into table! 3.150 - testEntry->content = entry->content; 3.151 - entry->content = NULL; 3.152 - freeHashEntryButNotContent( entry ); 3.153 - } 3.154 - return 1; 3.155 - } 3.156 - 3.157 -/*Better version 3.158 - */ 3.159 - void 3.160 -untested_putEntryIntoTable( HashEntry *entry, HashTable * table ) 3.161 - { HashEntry *testEntry, *prevEntry = NULL; 3.162 - unsigned int 3.163 - hashIndex = hashThisKey( entry->key, table->tableSz ); 3.164 - 3.165 - testEntry = table->entries[ hashIndex ]; 3.166 - for( ; testEntry != NULL; testEntry = testEntry->next ) 3.167 - { if( memcmp( testEntry->key, entry->key, sizeof(hashkey_t)) == 0 ) 3.168 - { if( prevEntry == NULL ) 3.169 - { table->entries[hashIndex] = entry; 3.170 - entry->next = testEntry->next; 3.171 - } 3.172 - else 3.173 - { prevEntry->next = entry; 3.174 - entry->next = testEntry->next; 3.175 - } 3.176 - freeHashEntryUsing( testEntry, table ); //frees content too! 3.177 - return; 3.178 - } 3.179 - } 3.180 - //wasn't found, so insert 3.181 - entry->next = table->entries[hashIndex]; 3.182 - table->entries[hashIndex] = entry; 3.183 - } 3.184 - 3.185 - 3.186 - 3.187 - bool8 3.188 -deleteEntryFromTable( char *key, HashTable *table ) 3.189 - { HashEntry *hashEntry; 3.190 - HashEntry **addrOfHashEntryPtr; 3.191 - unsigned int hashIndex; 3.192 - 3.193 - hashIndex = hashThisKey( key, table->tableSz ); 3.194 - addrOfHashEntryPtr = &( table->entries[ hashIndex ] ); 3.195 - hashEntry = *addrOfHashEntryPtr; 3.196 - while( hashEntry != NULL ) 3.197 - { if( memcmp( hashEntry->key, key, sizeof(hashkey_t) ) == 0 ) 3.198 - { 3.199 - *addrOfHashEntryPtr = hashEntry->next; 3.200 - //TODO: Free the contents of entry? 3.201 - freeHashEntryButNotContent( hashEntry ); 3.202 - table->numEntries -= 1; 3.203 - return TRUE; 3.204 - } 3.205 - addrOfHashEntryPtr = &( hashEntry->next ); 3.206 - hashEntry = *addrOfHashEntryPtr; 3.207 - } 3.208 - return FALSE; 3.209 - } 3.210 - 3.211 -void 3.212 -freeHashTable( HashTable *table ) 3.213 - { int i; 3.214 - HashEntry *hashEntry, *temp, **entries; 3.215 - 3.216 - entries = table->entries; 3.217 - for( i=0; i < table->tableSz; i++ ) 3.218 - { if( entries[i] != NULL ) 3.219 - { hashEntry = entries[i]; 3.220 - while( hashEntry != NULL ) 3.221 - { 3.222 - temp = hashEntry->next; 3.223 - freeHashEntryUsing( hashEntry, table ); 3.224 - hashEntry = temp; 3.225 - } 3.226 - } 3.227 - } 3.228 - } 3.229 - 3.230 -void 3.231 -freeHashEntryUsing( HashEntry *entry, HashTable *table ) 3.232 - { 3.233 - if( entry->content != NULL ) 3.234 - (*(table->freeEntryContentFn))( entry->content ); 3.235 - free( entry->key ); //was malloc'd above, so free it 3.236 - free( entry ); 3.237 - } 3.238 - 3.239 -void 3.240 -freeHashEntryButNotContent( HashEntry *entry ) 3.241 - { 3.242 - free( entry->key ); //was malloc'd above, so free it 3.243 - free( entry ); 3.244 - } 3.245 -
4.1 --- a/PrivateHash.h Sat Feb 11 18:00:56 2012 -0800 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,74 +0,0 @@ 4.4 -/* 4.5 - * Copyright 2009 OpenSourceStewardshipFoundation.org 4.6 - * Licensed under GNU General Public License version 2 4.7 - * 4.8 - * Author: seanhalle@yahoo.com 4.9 - */ 4.10 - 4.11 -#ifndef _PRIVATE_HASH_H 4.12 -#define _PRIVATE_HASH_H 4.13 - 4.14 - 4.15 -#include <stdio.h> 4.16 -#include <string.h> 4.17 -#include <errno.h> 4.18 -#include <stdlib.h> 4.19 - 4.20 -#define TRUE 1 4.21 -#define FALSE 0 4.22 - 4.23 -union hashkey_t{ 4.24 - char hashable[8]; 4.25 - int parts[2]; 4.26 -}; 4.27 - 4.28 -typedef union hashkey_t hashkey_t; 4.29 - 4.30 -#define DEFAULT_HASHSIZE 1 << 10 4.31 - 4.32 -typedef struct _HashEntry HashEntry; 4.33 - 4.34 -struct _HashEntry 4.35 - { 4.36 - char *key; 4.37 - void *content; 4.38 - HashEntry *next; 4.39 - }; 4.40 - 4.41 -typedef void (*FreeEntryContentFnPtr) ( void * ); 4.42 - 4.43 -typedef struct 4.44 - { int tableSz; 4.45 - int numEntries; 4.46 - HashEntry* *entries; 4.47 - FreeEntryContentFnPtr freeEntryContentFn; 4.48 - } 4.49 -HashTable; 4.50 - 4.51 - 4.52 -//=========================================================================== 4.53 -// Public functions 4.54 -HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); 4.55 - 4.56 -int putEntryIntoTable( HashEntry *entry, HashTable *table); 4.57 -int addValueIntoTable( char* key, void *value, HashTable *table); 4.58 -HashEntry *getEntryFromTable( char *key, HashTable *table ); 4.59 -void *getValueFromTable( char *key, HashTable *table ); 4.60 - 4.61 -bool8 deleteEntryFromTable( char *key, HashTable *table ); 4.62 -bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); 4.63 -bool8 deleteEntrysValueInTable( char *key, HashTable *table ); 4.64 -bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); 4.65 -void freeHashTable( HashTable *table ); 4.66 -//char *paramBagToString( ParamBag * bag ) 4.67 - 4.68 -//=========================================================================== 4.69 -// Internal functions 4.70 -void freeHashEntryUsing( HashEntry *entry, HashTable *table ); 4.71 -unsigned int hashThisKey( char *s, int hashSz ); 4.72 -void nullOutTablesArray( HashTable *table ); 4.73 -void doubleTableSize( HashTable *table ); 4.74 -void freeHashEntryButNotContent( HashEntry *entry ); 4.75 - 4.76 -#endif /* _PRIVATE_HASH_H */ 4.77 -
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/__brch__DEPRECATED_README Mon Feb 13 13:11:46 2012 -0800 5.3 @@ -0,0 +1,8 @@ 5.4 + 5.5 +There are two versions of the library -- one for pure C use, the other for use inside VMS or within applications written in a VMS-based language (IE, inside a top-level function or a call descendant of a top-level function) -- but only when the VMS is the "MC_shared" version. 5.6 + 5.7 +The reason is that VMS that uses shared memory on multicores moves the SlaveVPs around among cores. But, the libC and glibC malloc stores info at the top of the stack (a "clever" hack), for a speed improvement. So, when VMS manipulates the stack pointer, and/or moves Slaves to different cores, the "free" seg faults (that was FUN to figure out ; ) So, this version of VMS implements its own malloc. 5.8 + 5.9 +It is anticipated that the MC_split version, where each core has separate data, and messages are sent between cores, can handle malloc and free to use the glibC version. 5.10 + 5.11 +For now, update to the version of the library you wish to use..
