Add basic stat output to hash for testing.
Expose hash output functions for ecore_string. Move mask calculation outside inner loop for ecore_str_hash. SVN revision: 28006
This commit is contained in:
parent
3497296e2f
commit
8f497e0648
|
@ -248,6 +248,7 @@ extern "C" {
|
|||
EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
|
||||
EAPI void *ecore_hash_remove(Ecore_Hash *hash, const void *key);
|
||||
EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
|
||||
EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
|
||||
|
||||
|
||||
typedef struct _ecore_path_group Ecore_Path_Group;
|
||||
|
@ -360,6 +361,8 @@ extern "C" {
|
|||
EAPI void ecore_string_shutdown(void);
|
||||
EAPI const char *ecore_string_instance(const char *string);
|
||||
EAPI void ecore_string_release(const char *string);
|
||||
EAPI void ecore_string_hash_dump_graph();
|
||||
EAPI void ecore_string_hash_dump_stats();
|
||||
|
||||
|
||||
typedef struct _Ecore_Tree_Node Ecore_Tree_Node;
|
||||
|
|
|
@ -318,6 +318,33 @@ ecore_hash_dump_graph(Ecore_Hash *hash)
|
|||
printf("%d\t0\n", i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the distribution of the given hash table for graphing.
|
||||
* @param hash The given hash table.
|
||||
*/
|
||||
EAPI void
|
||||
ecore_hash_dump_stats(Ecore_Hash *hash)
|
||||
{
|
||||
unsigned int i;
|
||||
double variance, sum_n_2 = 0, sum_n = 0;
|
||||
|
||||
for (i = 0; i < ecore_prime_table[hash->size]; i++)
|
||||
{
|
||||
if (hash->buckets[i])
|
||||
{
|
||||
int n = 0;
|
||||
Ecore_Hash_Node *node;
|
||||
for (node = hash->buckets[i]; node; node = node->next)
|
||||
n++;
|
||||
sum_n_2 += ((double)n * (double)n);
|
||||
sum_n += (double)n;
|
||||
}
|
||||
}
|
||||
variance = (sum_n_2 - ((sum_n * sum_n) / (double)i)) / (double)i;
|
||||
printf("Average length: %f\n\tvariance^2: %f\n", (sum_n / (double)i),
|
||||
variance);
|
||||
}
|
||||
|
||||
static int
|
||||
_ecore_hash_bucket_destroy(Ecore_Hash_Node *list, Ecore_Free_Cb keyd, Ecore_Free_Cb valued)
|
||||
{
|
||||
|
|
|
@ -102,6 +102,18 @@ ecore_string_release(const char *string)
|
|||
}
|
||||
}
|
||||
|
||||
EAPI void
|
||||
ecore_string_hash_dump_graph()
|
||||
{
|
||||
ecore_hash_dump_graph(ecore_strings);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
ecore_string_hash_dump_stats()
|
||||
{
|
||||
ecore_hash_dump_stats(ecore_strings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the ecore string internal structures
|
||||
*/
|
||||
|
|
|
@ -67,16 +67,18 @@ EAPI unsigned int
|
|||
ecore_str_hash(const void *key)
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
unsigned int value = 0;
|
||||
const char *k = key;
|
||||
|
||||
if (!k)
|
||||
return 0;
|
||||
|
||||
mask = (sizeof(unsigned int) * 8) - 1;
|
||||
|
||||
for (i = 0; k[i] != '\0'; i++)
|
||||
{
|
||||
value ^= ((unsigned int) k[i] << ((i * 5) %
|
||||
(sizeof(unsigned int) * 8)));
|
||||
value ^= ((unsigned int) k[i] << ((i * 5) & mask));
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
Loading…
Reference in New Issue