| Bullet Collision Detection & Physics Library
    | 
 
 
 
Go to the documentation of this file.    1 #ifndef GIM_HASH_TABLE_H_INCLUDED 
    2 #define GIM_HASH_TABLE_H_INCLUDED 
   37 #define GIM_INVALID_HASH 0xffffffff   
   38 #define GIM_DEFAULT_HASH_TABLE_SIZE 380 
   39 #define GIM_DEFAULT_HASH_TABLE_NODE_SIZE 4 
   40 #define GIM_HASH_TABLE_GROW_FACTOR 2 
   42 #define GIM_MIN_RADIX_SORT_SIZE 860   
  105                 return ((
int)(a.m_key - key));
 
  116                 return ((
int)(a.m_key - b.m_key));
 
  124 template <
typename T>
 
  139 #define GIM_NUM_PRIME 28 
  143                 53ul, 97ul, 193ul, 389ul, 769ul,
 
  144                 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
 
  145                 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
 
  146                 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
 
  147                 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
 
  148                 1610612741ul, 3221225473ul, 4294967291ul};
 
  153         GUINT result_ind = 0;
 
  200                 while (start_index < end_index)
 
  205                                 if (nodesptr[value].m_key == hashkey) 
return start_index;
 
  220                 while (start_index < end_index)
 
  227                                         avaliable_index = start_index;
 
  230                         else if (nodesptr[value].m_key == hashkey)
 
  236                 return avaliable_index;
 
  246                 if (newtablesize == 0) 
return;
 
  261                 for (
GUINT i = 0; i < datasize; i++)
 
  341                 if (index >= 
m_nodes.size()) 
return false;
 
  441                 if (index >= 
m_nodes.size()) 
return false;
 
  482                 GUINT result_ind = 0;
 
  556                         if (reserve_size != 0)
 
  569                 else if (reserve_size != 0)
 
  588                 if (
size() < 2) 
return true;
 
  595                 if (
m_nodes.size() < 2) 
return false;
 
  635                 if (this->m_hash_table) 
return true;
 
  702                         if (
m_nodes[0].m_key == hashkey) 
return 0;
 
  708                         GUINT result_ind = 0;
 
  714                         if (found) 
return result_ind;
 
  734                 if (index > 
m_nodes.size()) 
return false;
 
  756                 if (index > 
m_nodes.size()) 
return false;
 
  774                 if (
size() == 0) 
return false;
 
  800                 for (i = 0; i < datasize; i++)
 
  857 #endif  // GIM_CONTAINERS_H_INCLUDED 
 
GUINT m_min_hash_table_size
Macro for getting the key.
bool operator>(const GIM_HASH_TABLE_NODE< T > &other) const
bool _erase_unsorted(GUINT index)
faster, but unsorted
bool switch_to_hashtable()
bool gim_binary_search(const T *_array, GUINT _start_i, GUINT _end_i, const T &_search_key, GUINT &_result_index)
Failsafe Iterative binary search,Template version.
Very simple array container with fast access and simd memory.
#define GIM_DEFAULT_HASH_TABLE_SIZE
bool erase_by_index(GUINT index)
GUINT insert_override(GUINT hashkey, const T &element)
Insert an element into the hash, and could overrite an existing object with the same hash.
GUINT find(GUINT hashkey)
Finds the index of the element with the key.
Macro for comparing Hash nodes.
void set_sorted(bool value)
GUINT _find_cell(GUINT hashkey)
Returns the cell index.
bool operator==(const GIM_HASH_TABLE_NODE< T > &other) const
void gim_radix_sort(T *array, GUINT element_count, GETKEY_CLASS get_uintkey_macro, COPY_CLASS copy_elements_macro)
Sorts array in place. For generic use.
bool switch_to_sorted_array()
GUINT _assign_hash_table_cell(GUINT hashkey)
Finds an avaliable hash table cell, and resizes the table if there isn't space.
GIM_HASH_TABLE_NODE< T > _node_type
GUINT _insert_hash_table_replace(GUINT hashkey, const T &value)
insert an element in hash table.
GUINT get_key(GUINT index) const
Retrieves the hash key.
bool _erase_sorted(GUINT index)
Sorted array data management. The hash table has the indices to the corresponding m_nodes array.
GUINT insert(GUINT hashkey, const T &element)
Insert an element into the hash.
void _rehash()
Invalidates the keys (Assigning GIM_INVALID_HASH to all) Reorders the hash keys.
gim_hash_table(GUINT reserve_size=GIM_DEFAULT_HASH_TABLE_SIZE, GUINT node_size=GIM_DEFAULT_HASH_TABLE_NODE_SIZE, GUINT min_hash_table_size=GIM_INVALID_HASH)
void _clear_table_memory()
Clear all memory for the hash table.
bool operator<(const GIM_HASH_TABLE_NODE< T > &other) const
GUINT gim_next_prime(GUINT number)
bool _erase_by_index_hash_table(GUINT index)
erase by index in hash table
static const GUINT gim_prime_list[GIM_NUM_PRIME]
GUINT size() const
Retrieves the amount of keys.
GUINT insert_unsorted(GUINT hashkey, const T &element)
Insert an element into the hash,But if this container is a sorted array, this inserts it unsorted.
Macro for comparing the key and the element.
GUINT operator()(const T &a)
T & operator[](GUINT index)
T * get_value(GUINT hashkey)
Retrieves the value associated with the index.
GIM_HASH_TABLE_NODE(GUINT key, const T &data)
void _resize_table(GUINT newsize)
Resize hash table indices.
#define GIM_DEFAULT_HASH_TABLE_NODE_SIZE
bool gim_binary_search_ex(const T *_array, GUINT _start_i, GUINT _end_i, GUINT &_result_index, const KEYCLASS &_search_key, COMP_CLASS _comp_macro)
Failsafe Iterative binary search,.
GUINT * m_hash_table
Hash table data management. The hash table has the indices to the corresponding m_nodes array.
A compact hash table implementation.
void _insert_in_pos(GUINT hashkey, const T &value, GUINT pos)
Insert in position ordered.
void _destroy()
Destroy hash table memory.
void _reserve_table_memory(GUINT newtablesize)
reserves the memory for the hash table.
GUINT _insert_hash_table(GUINT hashkey, const T &value)
insert an element in hash table
T * get_value_by_index(GUINT index)
Retrieves the value by index.
bool erase_by_index_unsorted(GUINT index)
GIM_HASH_TABLE_NODE(const GIM_HASH_TABLE_NODE &value)
GUINT _insert_sorted_replace(GUINT hashkey, const T &value)
const T & operator[](GUINT index) const
void * gim_alloc(size_t size)
Standar Memory functions.
bool _erase_hash_table(GUINT hashkey)
erase by key in hash table
gim_array< _node_type > m_nodes
The nodes.
#define GIM_INVALID_HASH
A very very high value.
Prototype for copying elements.
GUINT _insert_unsorted(GUINT hashkey, const T &value)
Fast insertion in m_nodes array.
bool check_for_switching_to_hashtable()
If the container reaches the.
bool erase_by_key(GUINT hashkey)
GUINT _find_avaliable_cell(GUINT hashkey)
Find the avaliable cell for the hashkey, and return an existing cell if it has the same hash key.
int operator()(const T &a, const T &b)
void gim_heap_sort(T *pArr, GUINT element_count, COMP_CLASS CompareFunc)
#define GIM_MIN_RADIX_SORT_SIZE
calibrated on a PIII
void gim_sort_hash_node_array(T *array, GUINT array_count)
Sorting for hash table.
GUINT _insert_sorted(GUINT hashkey, const T &value)
Insert an element in an ordered array.
int operator()(const T &a, GUINT key)