/********************************************************************* * * Copyright (C) 2001-2002, Simon Kagstrom * * Filename: hash_test.c * Description: A sample program to demonstrate the usage of the * generic hash table. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * $Id: hash_test.c 8461 2006-06-04 08:13:06Z ska $ * ********************************************************************/ #include /* malloc */ #include /* time */ #include /* errno */ #include /* perror etc */ #include "ght_hash_table.h" /* Include the generic hash table */ void fn(void *data, const void *key) { free(data); } int main(int argc, char *argv[]) { ght_hash_table_t *p_table; ght_hash_table_t *p_table2; ght_iterator_t iterator; int i_loops = 100000; int i_removed = 0; const void *p_key; void *p_e; int i; /* Initialise the random seed */ srand(1000); if (argc > 1) { /* Create two hash table with move to front heuristics, specifying the size for one. Both use automatic rehashing */ p_table = ght_create(atoi(argv[1])); ght_set_rehash(p_table, TRUE); ght_set_heuristics(p_table, GHT_HEURISTICS_MOVE_TO_FRONT); if (argc > 2) i_loops = atoi(argv[2]); p_table2 = ght_create(5000); ght_set_rehash(p_table2, TRUE); ght_set_heuristics(p_table2, GHT_HEURISTICS_MOVE_TO_FRONT); } else { /* Create two hash table with transpose heuristics, size 5000. Hash function is one_at_a_time_hash (default with NULL). */ p_table = ght_create(5000); ght_set_rehash(p_table, FALSE); ght_set_heuristics(p_table, GHT_HEURISTICS_TRANSPOSE); p_table2 = ght_create(5000); ght_set_rehash(p_table2, FALSE); ght_set_heuristics(p_table2, GHT_HEURISTICS_TRANSPOSE); } /* This is a bounded bucket implementation */ ght_set_bounded_buckets(p_table, 3, fn); /* Enter lots of stuff to the tables. */ for (i=0; ii_items > p_table->i_size*2) * ght_he_rehash(p_he); */ } printf("Inserted %d elements.\n", i_loops); /* Get the same stuff FROM the table */ for (i=0; i