From: Mike D. Lowis Date: Mon, 4 Jun 2012 16:14:15 +0000 (-0400) Subject: Delete hashtable implementation. A new map structure will be implemented using a... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=830d4e23bf0ef3be0f393b2351c405c210aa66e1;p=projs%2Flibcds.git Delete hashtable implementation. A new map structure will be implemented using a redblack tree. --- diff --git a/source/ht/ht.c b/source/ht/ht.c deleted file mode 100644 index f2fb2ba..0000000 --- a/source/ht/ht.c +++ /dev/null @@ -1,134 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2012, Michael D. Lowis - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ -#include "ht.h" -#include -#include -#include - -//unsigned int ht_hash_string(void* key) -//{ -// char* key_str = (char*)key; -// unsigned int hash = 0; -// int i = 0; -// for (i = 0; key_str[i] != '\0'; i++) -// { -// hash += key_str[i]; -// } -// return hash; -//} -// -//ht_table* ht_new(unsigned int size, ht_hash_func fn) -//{ -// unsigned int table_size = size * sizeof(ht_node*); -// ht_table* table = (ht_table*) malloc( sizeof(ht_table) ); -// table->size = size; -// table->table = (ht_node**) malloc( table_size ); -// table->hash_func = (fn != NULL) ? fn : ht_hash_string; -// memset(table->table, 0, table_size); -// return table; -//} -// -//void ht_free(ht_table* table, int free_key, int free_value) -//{ -// int i = 0; -// for (i = 0; i < table->size; i++) -// { -// ht_node* cur = table->table[i]; -// while (cur != NULL) -// { -// printf("Index: %d\tKey: %s\tVal: %#x\tNext: %#x\n", i, cur->key, (int)cur->val, (int)cur->next); -// ht_node* next = cur->next; -// free( cur->key ); -// free( cur->val ); -// free( cur ); -// cur = next; -// } -// } -//} -// -//void ht_put(ht_table* table, void* key, void* val) -//{ -// unsigned int index = table->hash_func( key ) % table->size; -// ht_node* cur = table->table[index]; -// ht_node* last = cur; -// -// while (cur != NULL) -// { -// if ( !strcmp( key, cur->key ) ) -// { -// cur->val = val; -// break; -// } -// last = cur; -// cur = cur->next; -// } -// -// if (cur == NULL) -// { -// ht_node* node = (ht_node*) malloc( sizeof(ht_node) ); -// node->key = (char*) strdup( key ); -// node->val = val; -// node->next = NULL; -// -// if (last != NULL) -// { -// last->next = node; -// } -// else -// { -// table->table[ index ] = node; -// } -// } -//} -// -//void* ht_get(ht_table* table, void* key) -//{ -// void* ret = NULL; -// unsigned int index= table->hash_func( key ) % table->size; -// ht_node* node = table->table[ index ]; -// while ( node != NULL ) -// { -// if ( !strcmp( key, node->key ) ) -// { -// ret = node->val; -// break; -// } -// node = node->next; -// } -// return ret; -//} -// -//void ht_delete(ht_table* table, void* key, int free_key, int free_value) -//{ -// return 0; -//} -// -//ht_table* ht_resize(ht_table* table, unsigned int size) -//{ -// return 0; -//} - diff --git a/source/ht/ht.h b/source/ht/ht.h deleted file mode 100644 index f0bcf11..0000000 --- a/source/ht/ht.h +++ /dev/null @@ -1,157 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2012, Michael D. Lowis - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ -#ifndef HT_H -#define HT_H - -//! Hash function for hashing keys in a hash table -typedef unsigned int (*ht_hash_func) (void*); - -//! A node in a hash table. -typedef struct ht_node -{ - //! Pointer to the key - void* key; - //! Pointer to the value - void* val; - //! Pointer to the next node in the collision chain - struct node* next; -} ht_node; - -//! A hash table -typedef struct -{ - //! Size of the internal table - unsigned int size; - //! Pointer to the internal hashing table - ht_node** table; - //! Function used for hashing elements - ht_hash_func hash_func; -} ht_table; - -/** - * @brief Takes a string key value and returns it's hashed value. - * - * This function takes a pointer to a string and returns a hash value based on - * the contents of the string. - * - * @param key Pointer to the string to hash. - * - * @return The hashed value of the key. - **/ -unsigned int ht_hash_string(void* key); - -/** - * @brief Creates a new hash table - * - * This fucntion creates a new empty hash table with an internal lookup table - * of the given size and the desired hash function. The hash function will be - * used for insertion, deletion, and lookup of elements within the table. If - * the hash function pointer is null then ht_hash_string is used. - * - * @param size The size of the table to use for storing data. - * @param fn The function to use for hasing keys. - * - * @return The newly created table. - **/ -ht_table* ht_new(unsigned int size, ht_hash_func fn); - -/** - * @brief Frees all memory used by the provided hash table. - * - * This function frees all memory allocated for the given table. If free_key or - * free_value are non-zero values then the key or value pointers are freed - * respectively. - * - * @param table The table to be freed. - * @param free_key Determines whether the key pointers will be freed. - * @param free_value Determines whether the value pointers will be freed. - **/ -void ht_free(ht_table* table, int free_key, int free_value); - -/** - * @brief Inserts a key/value pair into the provided table. - * - * This function inserts a new entry into the provided table containing the - * provided key and value pointers. The entry is placed in the table by hashing - * the key with the provided table's hash function. If an entry with an - * identical key exists, then the value pointer for that entry is changed to - * the provided value pointer. If free_value is a non-zero value then the old - * value pointer is also freed. - * - * @param table The table to be freed. - * @param key The key for the associated value. - * @param val The value to be associated with the key. - * @param free_value Determines whether or not to free the old value pointer. - **/ -void ht_insert(ht_table* table, void* key, void* val); - -/** - * @brief Retrieves a value from the provided table. - * - * This function looks up an entry in the table by hashing the key with the - * table's hash function. It then returns the pointer to the value of the found - * entry or a null pointer if no entry was found. - * - * @param table The table in which to find the associated value. - * @param key The key to lookup. - * - * @return A pointer to the value associated with the provided key. - **/ -void* ht_find(ht_table* table, void* key); - -/** - * @brief Deletes a key/value pair from the provided hash table. - * - * This function looks up an entry in the table by hashing the key with the - * table's hash function. If an entry is found then the memory allocated for - * the entry is freed. If free_key or free_value are non-zero values then the - * key or value pointers are freed respectively. - * - * @param table The table from which the key/value pait will be deleted. - * @param key The key for the key/value pair to be deleted. - * @param free_key Determines whether the key pointer will be freed. - * @param free_value Determines whether the value pointer will be freed. - **/ -void ht_delete(ht_table* table, void* key, int free_key, int free_value); - -/** - * @brief Resizes the underlying table used for storing key/value pairs. - * - * This function allocates a new internal lookup table of the given size to - * replace the internal table for the provided hash table. After the new talbe - * is created, all entries from the old table are rehahsed and inserted into - * the new lookup table. The new lookup table then replaces the old lookup - * table and the old lookup table is freed. - * - * @param table The table to be resized. - * @param size The new size for the table. - * - * @return A pointer to the resized table. - **/ -ht_table* ht_resize(ht_table* table, unsigned int size); - -#endif diff --git a/tests/test_avl.cpp b/tests/test_avl.cpp new file mode 100644 index 0000000..66c75db --- /dev/null +++ b/tests/test_avl.cpp @@ -0,0 +1,19 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "avl.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test XXX Function + //------------------------------------------------------------------------- + TEST(Verify_XXX) + { + } +} diff --git a/tests/test_bt.cpp b/tests/test_bt.cpp new file mode 100644 index 0000000..37606a3 --- /dev/null +++ b/tests/test_bt.cpp @@ -0,0 +1,19 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "bt.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test XXX Function + //------------------------------------------------------------------------- + TEST(Verify_XXX) + { + } +} diff --git a/tests/test_dll.cpp b/tests/test_dll.cpp new file mode 100644 index 0000000..4155a9c --- /dev/null +++ b/tests/test_dll.cpp @@ -0,0 +1,19 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "dll.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test XXX Function + //------------------------------------------------------------------------- + TEST(Verify_XXX) + { + } +} diff --git a/tests/test_rbt.cpp b/tests/test_rbt.cpp new file mode 100644 index 0000000..86a65a7 --- /dev/null +++ b/tests/test_rbt.cpp @@ -0,0 +1,19 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "rbt.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test XXX Function + //------------------------------------------------------------------------- + TEST(Verify_XXX) + { + } +} diff --git a/tests/test_sll.cpp b/tests/test_sll.cpp new file mode 100644 index 0000000..ffd8bf0 --- /dev/null +++ b/tests/test_sll.cpp @@ -0,0 +1,19 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "sll.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test XXX Function + //------------------------------------------------------------------------- + TEST(Verify_XXX) + { + } +}