/* * File hcreate.c. * * Copyright (C) 2005 Martin Str@"omberg . * * This software may be used freely so long as this copyright notice is * left intact. There is no warranty on this software. * */ #include #include #include /* * It's impossible to have hash table with more than 0x20000000 elements * as sizeof(ENTRY) == 8. */ #define MAX_BUCKETS 0x20000000 static ENTRY *hash = NULL; static size_t buckets = 0; static size_t mask = -1; int hcreate( size_t nel ) { size_t i; /* Fail anything > MAX_BUCKETS. */ if( MAX_BUCKETS < nel ) { return 0; } /* Increase with 1/3. */ nel += nel/3; /* Decrease to MAX_BUCKETS if necessary. */ if( MAX_BUCKETS < nel ) { nel = MAX_BUCKETS; } /* Minimum is 128 elements. Algorithm doesn't depend on this, though. */ i = 7; if( nel < 0x80 ) { nel = 0x80; } /* Round up to next power-of-2. */ while( (1U<