summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-03 19:55:22 +0100
committerTyge Løvset <[email protected]>2021-02-03 19:55:22 +0100
commit62a4ffee9682a79123ac8fdfaa331f324140aaf6 (patch)
tree69a5108d8a76ecf30a2f0482ba65fec7304f927d /examples
parenta1ed3586c5575d4f9094ae3dcc2cdf0911951b3e (diff)
downloadSTC-modified-62a4ffee9682a79123ac8fdfaa331f324140aaf6.tar.gz
STC-modified-62a4ffee9682a79123ac8fdfaa331f324140aaf6.zip
Two fixes in csmap. erase: value_del called on wrong node. Forgot calling skew and split 3 and 2 times in erase.
Diffstat (limited to 'examples')
-rw-r--r--examples/csmap_ex2.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/examples/csmap_ex2.c b/examples/csmap_ex2.c
index ebb0f6cf..b316d292 100644
--- a/examples/csmap_ex2.c
+++ b/examples/csmap_ex2.c
@@ -7,26 +7,43 @@
#endif
using_csmap(i, int, int);
-enum {N=10000000};
+enum {N=2000};
int main()
{
clock_t t1, t2, t3, t4, t5;
{
t1 = clock();
csmap_i map = csmap_i_init();
- stc64_srandom(1);
- c_forrange (i, N)
- csmap_i_emplace(&map, stc64_random() & 0xffffff, i);
- c_forrange (i, N/2)
- csmap_i_erase(&map, stc64_random() & 0xffffff);
+ stc64_srandom(123);
+ c_forrange (i, 12) {
+ int x = stc64_random() & 0xff;
+ csmap_i_emplace(&map, x, i);
+ printf(" %d", x);
+ }
+ puts("");
+ c_foreach (i, csmap_i, map) printf(" %d", i.ref->first);
+ puts("\n");
+ //c_foreach (i, csmap_i, map)
+ //printf("%d: %d\n", i.ref->first, i.ref->second);
+ printf("size %zu\n", csmap_i_size(map));
+
+ stc64_srandom(123);
+ c_forrange (i, 6) {
+ int x = stc64_random() & 0xff;
+ printf("Try erase: %d\n", x);
+ csmap_i_erase(&map, x);
+ c_foreach (i, csmap_i, map) printf(" %d", i.ref->first);
+ puts("");
+ }
t2 = clock();
size_t n = 0, sum = 0;
c_foreach (i, csmap_i, map)
sum += i.ref->first;
t3 = clock();
- c_foreach (i, csmap_i, map)
- if (n++ < 20) printf("%d: %d\n", i.ref->first, i.ref->second); else break;
+ //c_foreach (i, csmap_i, map)
+ //if (n++ < 20) printf("%d: %d\n", i.ref->first, i.ref->second); else break;
printf("size %zu: %zu\n", csmap_i_size(map), sum);
+
t4 = clock();
csmap_i_del(&map);
}