summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/carc_api.md4
-rw-r--r--examples/arc_containers.c2
-rw-r--r--examples/music_arc.c5
-rw-r--r--include/stc/carc.h4
-rw-r--r--include/stc/cbox.h4
-rw-r--r--include/stc/ccommon.h1
-rw-r--r--include/stc/cmap.h20
-rw-r--r--include/stc/template.h3
8 files changed, 24 insertions, 19 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md
index c8248b67..4dea2b2c 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -84,8 +84,8 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted pointer
-#define i_val_class Map // Note i_val_class: Map is a "class", i.e. has clone, drop functions.
-#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p)) // override Map_drop(p):
+#define i_val Map
+#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p))
#include <stc/carc.h>
#define i_type Stack
diff --git a/examples/arc_containers.c b/examples/arc_containers.c
index c4c68bcf..6e6f748f 100644
--- a/examples/arc_containers.c
+++ b/examples/arc_containers.c
@@ -9,7 +9,7 @@
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted type
-#define i_val_class Map
+#define i_val Map
#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p))
// no need for atomic ref. count in single thread:
#define i_opt c_no_atomic
diff --git a/examples/music_arc.c b/examples/music_arc.c
index 616114fc..0fb0dd70 100644
--- a/examples/music_arc.c
+++ b/examples/music_arc.c
@@ -21,9 +21,8 @@ void Song_drop(Song* s) {
// Define the reference counted type
#define i_type SongArc
-#define i_val Song
-#define i_valdrop Song_drop
-#define i_cmp Song_cmp
+#define i_val_class Song
+#define i_opt c_no_hash
#include <stc/carc.h>
// ... and a vector of it
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 6148a815..94dc9bd6 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -78,10 +78,10 @@ int main() {
#ifndef _i_prefix
#define _i_prefix carc_
#endif
-#if !(defined i_cmp || defined i_less)
+#if !(defined i_cmp || defined i_less || defined i_val_class)
#define _i_no_cmp
#endif
-#if !(defined i_eq || defined i_hash)
+#if !(defined i_eq || defined i_hash || defined i_val_class)
#define _i_no_hash
#endif
#include "template.h"
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 62bb506a..f31c5feb 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -70,10 +70,10 @@ int main() {
#ifndef _i_prefix
#define _i_prefix cbox_
#endif
-#if !(defined i_cmp || defined i_less)
+#if !(defined i_cmp || defined i_less || defined i_val_class)
#define _i_no_cmp
#endif
-#if !(defined i_eq || defined i_hash)
+#if !(defined i_eq || defined i_hash || defined i_val_class)
#define _i_no_hash
#endif
#include "template.h"
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 52c05693..5ecb42f8 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -111,6 +111,7 @@
#define c_no_atomic (1<<1)
#define c_no_clone (1<<2)
#define c_no_cmp (1<<3)
+#define c_no_hash (1<<4)
/* Generic algorithms */
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 659b89f7..ed8a81c8 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -361,15 +361,17 @@ _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey) {
#if !defined _i_no_clone
STC_DEF _cx_self
_cx_memb(_clone)(_cx_self m) {
- _cx_value *t = c_alloc_n(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count;
- uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1);
- if (!(t && h))
- { c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; }
- else
- for (; m.table != m_end; ++m.table, ++m._hashx, ++dst)
- if (*m._hashx)
- *dst = _cx_memb(_value_clone)(*m.table);
- m.table = t, m._hashx = h;
+ if (m.table) {
+ _cx_value *t = c_alloc_n(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count;
+ uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1);
+ if (!(t && h))
+ { c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; }
+ else
+ for (; m.table != m_end; ++m.table, ++m._hashx, ++dst)
+ if (*m._hashx)
+ *dst = _cx_memb(_value_clone)(*m.table);
+ m.table = t, m._hashx = h;
+ }
return m;
}
#endif
diff --git a/include/stc/template.h b/include/stc/template.h
index f8d9e7b7..000b516e 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -163,6 +163,9 @@
#if c_option(c_no_cmp)
#define _i_no_cmp
#endif
+#if c_option(c_no_hash)
+ #define _i_no_hash
+#endif
#if c_option(c_no_clone) || (!defined i_keyclone && (defined i_keydrop || defined i_keyraw))
#define _i_no_clone
#endif