This commit is contained in:
2026-05-19 16:16:03 -06:00
parent c1851fe242
commit 78a4fb402d
5 changed files with 48 additions and 23 deletions
BIN
View File
Binary file not shown.
+33 -22
View File
@@ -1,11 +1,38 @@
#include <stdio.h>
#include <string.h>
#include "../runtime/gyehoek.h"
#include "../runtime/weak-set.h"
static int
symbol_lookup_predicate_fn (SCM sym, void *closure) {
SCM other = SCM_PACK_POINTER (closure);
return 1;
symbol_lookup_predicate_fn (SCM sym1, void *closure) {
const SCM sym2 = *((SCM*)closure);
const int symp1 = SCM_SYMBOLP (sym1);
const int symp2 = SCM_SYMBOLP (sym2);
// both symbols?
if (SCM_SYMBOLP (sym1) && SCM_SYMBOLP (sym2)) {
const SCM str1 = SCM_CELL_OBJECT (sym1, 2);
const SCM str2 = SCM_CELL_OBJECT (sym2, 2);
const size_t len1 = scm_c_string_length (str1);
const size_t len2 = scm_c_string_length (str2);
// same length?
if (len1 == len2) {
// same name?
const char * const s1 = scm_c_string_chars (str1);
const char * const s2 = scm_c_string_chars (str2);
return strncmp (s1, s2, len1);
}
}
return 0;
}
SCM test (SCM set, const char *sym_name, SCM value) {
SCM str = scm_from_cstring (sym_name);
SCM sym = scm_make_symbol (str, scm_c_hash (str));
SCM r = scm_c_weak_set_insert (set, scm_c_hash (str), value,
symbol_lookup_predicate_fn,
&sym);
printf ("%ld\n", weak_set_count (set));
return r;
}
int main () {
@@ -15,23 +42,7 @@ int main () {
/* printf ("%ld\n", hash); */
SCM set = scm_c_make_weak_set (31);
SCM str = scm_from_cstring ("my-symbol");
SCM sym = scm_make_symbol (str, scm_c_hash (str));
scm_c_weak_set_insert (set, scm_c_hash (str),
SCM_PACK (SCM_MAKE_SMALL_INT (123)),
symbol_lookup_predicate_fn,
SCM_UNPACK_POINTER (sym));
printf ("%ld\n", weak_set_count (set));
scm_c_weak_set_insert (set, scm_c_hash (str),
SCM_PACK (SCM_MAKE_SMALL_INT (123)),
symbol_lookup_predicate_fn,
SCM_UNPACK_POINTER (sym));
printf ("%ld\n", weak_set_count (set));
SCM str2 = scm_from_cstring ("my-symbol2");
SCM sym2 = scm_make_symbol (str2, scm_c_hash (str2));
scm_c_weak_set_insert (set, scm_c_hash (str2),
SCM_PACK (SCM_MAKE_SMALL_INT (456)),
symbol_lookup_predicate_fn,
SCM_UNPACK_POINTER (sym2));
printf ("%ld\n", weak_set_count (set));
test (set, "my-symbol", SCM_PACK (SCM_MAKE_SMALL_INT (123)));
test (set, "my-symbol", SCM_PACK (SCM_MAKE_SMALL_INT (123)));
test (set, "my-symbol2", SCM_PACK (SCM_MAKE_SMALL_INT (456)));
}