summaryrefslogtreecommitdiffhomepage
path: root/cmap_test.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-05 09:14:53 +0100
committerGitHub <[email protected]>2020-03-05 09:14:53 +0100
commit4e3efe66adc1048168f1ebb7faaf7e7153c4d454 (patch)
treed3ffefedfa7bb084100571fae01734ce8d39215a /cmap_test.c
parentdbeb3f14de419d2e9565f719a6a03a88861feefc (diff)
downloadSTC-modified-4e3efe66adc1048168f1ebb7faaf7e7153c4d454.tar.gz
STC-modified-4e3efe66adc1048168f1ebb7faaf7e7153c4d454.zip
Add files via upload
Diffstat (limited to 'cmap_test.c')
-rw-r--r--cmap_test.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/cmap_test.c b/cmap_test.c
index 0bcbaefa..7c5e1fad 100644
--- a/cmap_test.c
+++ b/cmap_test.c
@@ -1,3 +1,25 @@
+// MIT License
+//
+// Copyright (c) 2020 Tyge Løvset, NORCE, www.norceresearch.no
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
#include <stdio.h>
#include <stdlib.h>
@@ -23,7 +45,7 @@ char *fgetstr(char *string, int n, FILE *stream)
return string;
}
-int read_words(CMap(si)* map)
+int read_words(CMap_si* map)
{
FILE * fp;
# define bufferLength 1024
@@ -49,11 +71,12 @@ int main()
{
int i = 0;
- CMap(si) words = cmap_initializer;
+ CMap_si words = cmap_initializer;
+
printf("read words\n");
read_words(&words);
- CMapEntry(si)* num = NULL;
+ CMapEntry_si* num = NULL;
num = cmap_si_get(words, "hello");
if (num) printf("%s: %d\n", num->key.str, num->value);
@@ -63,7 +86,7 @@ int main()
printf("words size: %d, capacity %d\n", cmap_size(words), cmap_capacity(words));
cmap_si_clear(&words);
- CVector(s) strv = cvector_initializer;
+ CVector_s strv = cvector_initializer;
CString hello = cstring_make("Hello");
cstring_assign(&hello, "Awesome");
@@ -72,8 +95,8 @@ int main()
cvector_s_push(&strv, cstring_make("E2"));
printf(" element %d: %s\n", 1, strv.data[1].str);
- CVectorIter(s) ii; cforeach (ii, cvector_s, strv) {
- printf(" %s\n", ii.item->str);
+ cforeach (i, cvector_s, strv) {
+ printf(" %s\n", i.item->str);
}
for (i = 0; i < cvector_size(strv); ++i) {
@@ -81,30 +104,27 @@ int main()
}
cvector_s_destroy(&strv);
- CMap(ss) smap = cmap_initializer;
+ 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_clone(hello));
-
cstring_destroy(&hello);
- CMapIter(ss) kk = cmap_ss_begin(smap), end2 = cmap_ss_end(smap);
- for (; kk.item != end2.item; kk = cmap_ss_next(kk)) {
- printf(" %s: %s\n", kk.item->key.str, kk.item->value.str);
- }
+ cforeach (i, cmap_ss, smap)
+ printf(" %s: %s\n", i.item->key.str, i.item->value.str);
cmap_ss_destroy(&smap);
- CMap(id) mymap = cmap_initializer;
+ CMap_id mymap = cmap_initializer;
for (i = 0; i < 600000; ++i)
cmap_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);
- CMapEntry(id)* me = cmap_id_get(mymap, 10000);
- printf("untouched: %d %f\n", me->untouched, me->value);
+ CMapEntry_id* me = cmap_id_get(mymap, 10000);
+ printf("changed: %d %f\n", me->changed, me->value);
cmap_id_put(&mymap, 10000, 101.2);
- printf("untouched: %d %f\n", me->untouched, me->value);
+ printf("changed: %d %f\n", me->changed, me->value);
cmap_id_destroy(&mymap);
}