diff options
| author | tylo <[email protected]> | 2020-03-11 11:50:00 +0100 |
|---|---|---|
| committer | tylo <[email protected]> | 2020-03-11 11:50:00 +0100 |
| commit | 4da2cdc45522626d005a0221a73064f0217b69fe (patch) | |
| tree | 2d22ba16bd786f9f762af9cd9c7ad55be84acedf /cmap_test.c | |
| parent | 7c326f3effd9977cb34e23d9cc9e9eb42ae3c789 (diff) | |
| download | STC-modified-4da2cdc45522626d005a0221a73064f0217b69fe.tar.gz STC-modified-4da2cdc45522626d005a0221a73064f0217b69fe.zip | |
New API: c_
Diffstat (limited to 'cmap_test.c')
| -rw-r--r-- | cmap_test.c | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/cmap_test.c b/cmap_test.c index ca773fdb..39715b3d 100644 --- a/cmap_test.c +++ b/cmap_test.c @@ -24,14 +24,14 @@ #include <stdlib.h>
#include <time.h>
-#include "cmap.h"
-#include "cstring.h"
+#include "c_hashmap.h"
+#include "c_string.h"
-declare_CStringVector(s);
-declare_CMap_StringKey(ss, CString, cstring_destroy);
-declare_CMap_StringKey(si, int);
-declare_CMap(id, uint64_t, double);
+declare_c_StringVector(s);
+c_declare_Hashmap_stringkey(ss, c_String, c_string_destroy);
+c_declare_Hashmap_stringkey(si, int);
+c_declare_Hashmap(id, uint64_t, double);
// like fgets, but removes any newline
@@ -46,7 +46,7 @@ char *fgetstr(char *string, int n, FILE *stream) return string;
}
-int read_words(CMap_si* map)
+int read_words(c_Hashmap_si* map)
{
FILE * fp;
# define bufferLength 1024
@@ -61,7 +61,7 @@ int read_words(CMap_si* map) while (fgetstr(line, bufferLength, fp)) {
++i;
if (i < 10) printf("%zu: %s\n", i, line);
- cmap_si_put(map, line, i);
+ c_hashmap_si_put(map, line, i);
}
fclose(fp);
@@ -69,20 +69,20 @@ int read_words(CMap_si* map) }
void stringSpeed(int limit) {
- CString s = cstring_initializer;
+ c_String s = c_string_initializer;
char ch[2] = {0, 0};
size_t x = 0;
size_t p = 0;
- for (int n = 0; n < limit; ++n) { ch[0] = 'A' + (rand() % 26); cstring_append(&s, ch); }
+ for (int n = 0; n < limit; ++n) { ch[0] = 'A' + (rand() % 26); c_string_append(&s, ch); }
const char* search = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
- cstring_append(&s, search);
+ c_string_append(&s, search);
clock_t before = clock();
for (int n = 0; n < limit; ++n) {
- p = cstring_find(s, 0, search + (n % 100));
- if (p != cstring_npos) x += p;
+ p = c_string_find(s, 0, search + (n % 100));
+ if (p != c_string_npos) x += p;
}
clock_t diff = clock() - before;
- printf("cstring length = %llu / %llu, sum %llu speed: %f\n", cstring_size(s), cstring_capacity(s), x, 1.0 * diff / CLOCKS_PER_SEC);
+ printf("cstring length = %llu / %llu, sum %llu speed: %f\n", c_string_size(s), c_string_capacity(s), x, 1.0 * diff / CLOCKS_PER_SEC);
}
int main()
@@ -91,73 +91,73 @@ int main() stringSpeed(20000);
- CString cs = cstring_make("one-nine-three-seven-five");
+ c_String cs = c_string_make("one-nine-three-seven-five");
printf("%s.\n", cs.str);
- cstring_insert(&cs, 3, "-two");
+ c_string_insert(&cs, 3, "-two");
printf("%s.\n", cs.str);
- cstring_erase(&cs, 7, 5); // -nine
+ c_string_erase(&cs, 7, 5); // -nine
printf("%s.\n", cs.str);
- cstring_replace(&cs, 0, "seven", "four");
+ c_string_replace(&cs, 0, "seven", "four");
printf("%s.\n", cs.str);
- printf("found: %s\n", cs.str + cstring_find(cs, 0, "four"));
- cstring_assign(&cs, "one two three four five six seven");
- cstring_replace(&cs, 0, "four", "F-O-U-R");
+ printf("found: %s\n", cs.str + c_string_find(cs, 0, "four"));
+ c_string_assign(&cs, "one two three four five six seven");
+ c_string_replace(&cs, 0, "four", "F-O-U-R");
printf("replace: %s\n", cs.str);
- CMap_si words = cmap_initializer;
+ c_Hashmap_si words = c_hashmap_initializer;
printf("read words\n");
read_words(&words);
- CMapEntry_si* num = NULL;
- num = cmap_si_get(words, "hello");
+ c_HashmapEntry_si* num = NULL;
+ num = c_hashmap_si_get(words, "hello");
if (num) printf("%s: %d\n", num->key.str, num->value);
- num = cmap_si_get(words, "funny");
+ num = c_hashmap_si_get(words, "funny");
if (num) printf("%s: %d\n", num->key.str, num->value);
- printf("words size: %llu, capacity %llu\n", cmap_size(words), cmap_buckets(words));
- cmap_si_clear(&words);
+ printf("words size: %llu, capacity %llu\n", c_hashmap_size(words), c_hashmap_buckets(words));
+ c_hashmap_si_clear(&words);
- CVector_s strv = cvector_initializer;
- CString myday = cstring_make("my day");
- cstring_assign(&myday, "great");
+ c_Vector_s strv = c_vector_initializer;
+ c_String myday = c_string_make("my day");
+ c_string_assign(&myday, "great");
- cvector_s_push(&strv, cstring_make("E0"));
- cvector_s_push(&strv, cstring_make("E1"));
- cvector_s_push(&strv, cstring_make("E2"));
+ c_vector_s_push(&strv, c_string_make("E0"));
+ c_vector_s_push(&strv, c_string_make("E1"));
+ c_vector_s_push(&strv, c_string_make("E2"));
printf(" element %d: %s\n", 1, strv.data[1].str);
- cforeach (i, cvector_s, strv) {
+ c_foreach (i, c_vector_s, strv) {
printf(" %s\n", i.item->str);
}
- for (i = 0; i < cvector_size(strv); ++i) {
+ for (i = 0; i < c_vector_size(strv); ++i) {
printf(" %s\n", strv.data[i].str);
}
- cvector_s_destroy(&strv);
+ c_vector_s_destroy(&strv);
- CMap_ss smap = cmap_initializer;
- cmap_ss_put(&smap, "KEY1", cstring_make("VAL1"));
- cmap_ss_put(&smap, "KEY2", cstring_make("VAL2"));
- cmap_ss_put(&smap, "hello", cstring_makeCopy(myday));
- cstring_destroy(&myday);
+ c_Hashmap_ss smap = c_hashmap_initializer;
+ c_hashmap_ss_put(&smap, "KEY1", c_string_make("VAL1"));
+ c_hashmap_ss_put(&smap, "KEY2", c_string_make("VAL2"));
+ c_hashmap_ss_put(&smap, "hello", c_string_makeCopy(myday));
+ c_string_destroy(&myday);
- cforeach (i, cmap_ss, smap)
+ c_foreach (i, c_hashmap_ss, smap)
printf(" %s: %s\n", i.item->key.str, i.item->value.str);
- cmap_ss_destroy(&smap);
+ c_hashmap_ss_destroy(&smap);
- CMap_id mymap = cmap_initializer;
+ c_Hashmap_id mymap = c_hashmap_initializer;
for (i = 0; i < 600000; ++i)
- cmap_id_put(&mymap, i*i, i);
+ c_hashmap_id_put(&mymap, i*i, i);
for (i = 1000; i < 1010; ++i)
- printf("lookup %d: %f\n", i*i, cmap_id_get(mymap, i*i)->value);
+ printf("lookup %d: %f\n", i*i, c_hashmap_id_get(mymap, i*i)->value);
- CMapEntry_id* me = cmap_id_get(mymap, 10000);
+ c_HashmapEntry_id* me = c_hashmap_id_get(mymap, 10000);
printf("changed: %d %f\n", me->changed, me->value);
- cmap_id_put(&mymap, 10000, 101.2);
+ c_hashmap_id_put(&mymap, 10000, 101.2);
printf("changed: %d %f\n", me->changed, me->value);
- cmap_id_destroy(&mymap);
+ c_hashmap_id_destroy(&mymap);
}
|
