6#include "testing/testing.h"
8#define GHASH_INTERNAL_API
28# define TEXT_CORPUS_PATH "../../../../../eng_wikipedia_2010_1M-sentences.txt"
42 double lf, var, pempty, poverloaded;
46 "GHash stats (%u entries):\n\t"
47 "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: "
49 "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n",
65#ifdef TEXT_CORPUS_PATH
68 if (
data !=
nullptr) {
73 if (
data ==
nullptr) {
81 printf(
"\n========== STARTING %s ==========\n",
id);
97 char *p, *
w, *c_p, *c_w;
98 for (p = c_p = data_p,
w = c_w = data_w; *c_w; c_w++, c_p++) {
110 else if (*c_w ==
' ') {
129 for (p =
w = c = data_bis; *c; c++) {
138 else if (*c ==
' ') {
151 MEM_delete(data_bis);
153 printf(
"========== ENDED %s ==========\n\n",
id);
156template<
typename MapType>
static void str_map_tests(MapType &map,
const char *
id)
158 printf(
"\n========== STARTING %s ==========\n",
id);
169 map.reserve(strlen(
data) / 32);
174 char *p, *
w, *c_p, *c_w;
175 for (p = c_p = data_p,
w = c_w = data_w; *c_w; c_w++, c_p++) {
183 else if (*c_w ==
' ') {
191 map.print_stats(
"map");
200 for (p =
w = c = data_bis; *c; c++) {
209 else if (*c ==
' ') {
221 MEM_delete(data_bis);
223 printf(
"========== ENDED %s ==========\n\n",
id);
250 printf(
"\n========== STARTING %s ==========\n",
id);
290 printf(
"========== ENDED %s ==========\n\n",
id);
293template<
typename MapType>
296 printf(
"\n========== STARTING %s ==========\n",
id);
311 map.print_stats(
"map");
317 int v = map.lookup(i);
332 printf(
"========== ENDED %s ==========\n\n",
id);
343TEST(ghash, IntGHash100000000)
359TEST(ghash, IntMurmur2a100000000)
374TEST(ghash, IntMap100000000)
377 int_map_tests(map,
"IntMap - DefaultHash - 100000000", 100000000);
385 printf(
"\n========== STARTING %s ==========\n",
id);
390 for (
uint i = 0; i < count; i++) {
401 for (
uint i = 0; i < count; i++) {
411 for (
uint i = 0; i < count; i++) {
420 printf(
"========== ENDED %s ==========\n\n",
id);
423template<
typename MapType>
426 printf(
"\n========== STARTING %s ==========\n",
id);
431 for (
uint i = 0; i < count; i++) {
442 for (
uint i = 0; i < count; i++) {
448 map.print_stats(
"map");
452 for (
uint i = 0; i < count; i++) {
454 int v = map.lookup(dt);
459 printf(
"========== ENDED %s ==========\n\n",
id);
470TEST(ghash, IntRandGHash50000000)
478TEST(ghash, IntRandMurmur2a12000)
486TEST(ghash, IntRandMurmur2a50000000)
501TEST(ghash, IntRandMap50000000)
526TEST(ghash, IntRandNoHash50000000)
538 printf(
"\n========== STARTING %s ==========\n",
id);
544 for (
uint i = 0; i < count; i++) {
546 for (
int j = 0; j < 4; j++) {
559 for (
uint i = 0; i < count; i++) {
568 for (
uint i = 0; i < count; i++) {
576 printf(
"========== ENDED %s ==========\n\n",
id);
579template<
typename MapType>
582 printf(
"\n========== STARTING %s ==========\n",
id);
588 for (
uint i = 0; i < count; i++) {
590 for (
int j = 0; j < 4; j++) {
603 for (
uint i = 0; i < count; i++) {
604 map.add_new(
data[i], i);
608 map.print_stats(
"map");
612 for (
uint i = 0; i < count; i++) {
613 int v = map.lookup(
data[i]);
618 printf(
"========== ENDED %s ==========\n\n",
id);
630TEST(ghash, Int4GHash20000000)
648TEST(ghash, Int4Murmur2a20000000)
664TEST(ghash, Int4Map20000000)
667 int4_map_tests(map,
"Int4Map - DefaultHash - 20000000", 20000000);
680 for (i = count, dt =
data; i--; dt++) {
688 for (i = count, dt =
data; i--; dt++) {
692 for (i = count, dt =
data; i--; dt++) {
703 printf(
"\n========== STARTING %s ==========\n",
id);
712 (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
721 (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
729 printf(
"========== ENDED %s ==========\n\n",
id);
732TEST(ghash, MultiRandIntGHash2000)
739TEST(ghash, MultiRandIntGHash200000)
746TEST(ghash, MultiRandIntMurmur2a2000)
753TEST(ghash, MultiRandIntMurmur2a200000)
File and directory operations.
#define BLI_ghashutil_uinthash_v4_p_murmur
#define BLI_ghashutil_uinthash_v4_p
#define SCOPED_TIMER(name)
Read Blender memory allocation and freeing.
#define POINTER_FROM_INT(i)
#define POINTER_AS_UINT(i)
#define POINTER_AS_INT(i)
#define POINTER_FROM_UINT(i)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static void int4_map_tests(MapType &map, const char *id, const uint count)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void randint_ghash_tests(GHash *ghash, const char *id, const uint count)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
static void int4_ghash_tests(GHash *ghash, const char *id, const uint count)
static uint ghashutil_tests_nohash_p(const void *p)
VecBase< uint32_t, 4 > uint4
static void multi_small_ghash_tests_one(GHash *ghash, RNG *rng, const uint count)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void int_map_tests(MapType &map, const char *id, const uint count)
struct RNG * BLI_rng_new(unsigned int seed)
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr)
bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
double BLI_ghash_calc_quality_ex(const GHash *gh, double *r_load, double *r_variance, double *r_prop_empty_buckets, double *r_prop_overloaded_buckets, int *r_biggest_bucket)
char * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
static void int_ghash_tests(GHash *ghash, const char *id, const uint count)
static void randint_map_tests(MapType &map, const char *id, const uint count)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
static constexpr size_t TESTCASE_SIZE_SMALL
BMesh const char void * data
unsigned int BLI_rng_get_uint(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
bool BLI_ghashutil_intcmp(const void *a, const void *b)
static constexpr bool USE_RESERVE_COUNT
static bool ghashutil_tests_cmp_p(const void *a, const void *b)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
unsigned int BLI_ghashutil_inthash_p_murmur(const void *ptr)
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static char * read_text_corpus()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void BLI_ghash_reserve(GHash *gh, unsigned int nentries_reserve)
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
bool BLI_ghash_pop(GHash *gh, GHashIterState *state, void **r_key, void **r_val) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void str_ghash_tests(GHash *ghash, const char *id)
static void print_ghash_stats(GHash *gh)
static void str_map_tests(MapType &map, const char *id)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
unsigned int BLI_ghashutil_inthash_p(const void *ptr)
static void multi_small_ghash_tests(GHash *ghash, const char *id, const uint count)
bool BLI_ghash_haskey(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
bool BLI_ghashutil_strcmp(const void *a, const void *b)