2014-09-11 04:01:32 +04:00
|
|
|
/* g/h.c
|
2014-09-05 23:55:16 +04:00
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
|
2017-11-04 23:53:21 +03:00
|
|
|
static void _ch_free_node(u3h_node*, c3_w);
|
|
|
|
static void _ch_node_deflate(u3h_slot*, c3_w);
|
|
|
|
static c3_c* _ch_pre(c3_w);
|
|
|
|
static void _ch_print_node(u3h_node*, c3_w);
|
|
|
|
static void* _ch_some_add(void*, c3_w, c3_w, u3_noun, c3_w*);
|
2014-09-05 23:55:16 +04:00
|
|
|
static void* _ch_some_new(c3_w lef_w);
|
2017-11-04 23:53:21 +03:00
|
|
|
static void _ch_trim_one(u3h_root*);
|
|
|
|
static c3_o _ch_trim_one_some(u3h_slot*, c3_w);
|
|
|
|
static c3_o _ch_trim_one_buck(u3h_slot*);
|
|
|
|
static c3_o _ch_trim_one_node(u3h_slot*, c3_w);
|
|
|
|
static void _ch_walk_node(u3h_node*, c3_w, void (*fun_f)(u3_noun));
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-03 01:39:57 +03:00
|
|
|
/* u3h_new_cache(): create hashtable with bounded size.
|
|
|
|
*/
|
2014-11-06 03:20:01 +03:00
|
|
|
u3p(u3h_root)
|
2017-11-02 04:03:46 +03:00
|
|
|
u3h_new_cache(c3_w clk_w)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3a_walloc(c3_wiseof(u3h_root));
|
|
|
|
u3p(u3h_root) har_p = u3of(u3h_root, har_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
c3_w i_w;
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
har_u->clk_w = clk_w;
|
|
|
|
har_u->use_w = 0;
|
2014-09-05 23:55:16 +04:00
|
|
|
for ( i_w = 0; i_w < 64; i_w++ ) {
|
|
|
|
har_u->sot_w[i_w] = 0;
|
|
|
|
}
|
2014-11-04 04:02:55 +03:00
|
|
|
return har_p;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
/* u3h_new(): create hashtable.
|
|
|
|
*/
|
|
|
|
u3p(u3h_root)
|
|
|
|
u3h_new(void)
|
|
|
|
{
|
|
|
|
return u3h_new_cache(0);
|
|
|
|
}
|
|
|
|
|
2014-09-05 23:55:16 +04:00
|
|
|
/* _ch_popcount(): number of bits set in word. A standard intrinsic.
|
|
|
|
*/
|
|
|
|
static c3_w
|
|
|
|
_ch_popcount(c3_w num_w)
|
|
|
|
{
|
|
|
|
return __builtin_popcount(num_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_buck_new(): create new, empty bucket.
|
|
|
|
*/
|
2014-11-06 03:20:01 +03:00
|
|
|
static u3h_buck*
|
2014-09-05 23:55:16 +04:00
|
|
|
_ch_buck_new(void)
|
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_buck* hab_u = u3a_walloc(c3_wiseof(u3h_buck));
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
hab_u->len_w = 0;
|
2017-11-04 03:03:53 +03:00
|
|
|
hab_u->arm_w = 0;
|
2014-09-05 23:55:16 +04:00
|
|
|
return hab_u;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ha_buck_add(): add to bucket.
|
|
|
|
*/
|
2014-11-06 03:20:01 +03:00
|
|
|
static u3h_buck*
|
2017-11-02 04:03:46 +03:00
|
|
|
_ch_buck_add(u3h_buck* hab_u, u3_noun kev, c3_w *use_w)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
c3_w i_w;
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// if our key is equal to any of the existing keys in the bucket,
|
|
|
|
// then replace that key-value pair with kev.
|
|
|
|
//
|
2014-09-05 23:55:16 +04:00
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
u3_noun kov = u3h_slot_to_noun(hab_u->sot_w[i_w]);
|
|
|
|
if ( c3y == u3r_sing(u3h(kev), u3h(kov)) ) {
|
|
|
|
u3a_lose(kov);
|
|
|
|
hab_u->sot_w[i_w] = u3h_noun_to_slot(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
return hab_u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// create mutant bucket with added key-value pair.
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2017-11-02 04:03:46 +03:00
|
|
|
c3_w len_w = hab_u->len_w;
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_buck* bah_u = u3a_walloc(c3_wiseof(u3h_buck) +
|
2017-11-02 04:03:46 +03:00
|
|
|
(len_w + 1) * c3_wiseof(u3h_slot));
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
bah_u->arm_w = hab_u->arm_w + 1;
|
|
|
|
bah_u->len_w = len_w + 1;
|
|
|
|
bah_u->sot_w[0] = u3h_noun_to_slot(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
// Optimize: use u3a_wealloc().
|
2014-09-05 23:55:16 +04:00
|
|
|
//
|
2017-11-04 03:03:53 +03:00
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
bah_u->sot_w[i_w + 1] = hab_u->sot_w[i_w];
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-25 01:41:47 +03:00
|
|
|
u3a_wfree(hab_u);
|
2017-11-02 04:03:46 +03:00
|
|
|
*use_w += 1;
|
2014-09-05 23:55:16 +04:00
|
|
|
return bah_u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_node_new(): create new, empty node.
|
|
|
|
*/
|
2014-11-06 03:20:01 +03:00
|
|
|
static u3h_node*
|
2014-09-05 23:55:16 +04:00
|
|
|
_ch_node_new(void)
|
|
|
|
{
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "node_new\r\n");
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_node* han_u = u3a_walloc(c3_wiseof(u3h_node));
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
han_u->map_w = 0;
|
2017-11-04 03:03:53 +03:00
|
|
|
han_u->arm_w = 0;
|
2014-09-05 23:55:16 +04:00
|
|
|
return han_u;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_node_add(): add to node.
|
|
|
|
*/
|
2014-11-06 03:20:01 +03:00
|
|
|
static u3h_node*
|
2017-11-02 04:03:46 +03:00
|
|
|
_ch_node_add(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun kev, c3_w *use_w)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
c3_w bit_w, inx_w, map_w, i_w;
|
2017-11-04 23:53:21 +03:00
|
|
|
c3_c* pre = _ch_pre(lef_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
bit_w = (rem_w >> lef_w);
|
|
|
|
rem_w = (rem_w & ((1 << lef_w) - 1));
|
|
|
|
map_w = han_u->map_w;
|
|
|
|
inx_w = _ch_popcount(map_w & ((1 << bit_w) - 1));
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// there is already an entry at the slot with this index
|
|
|
|
//
|
2014-09-05 23:55:16 +04:00
|
|
|
if ( map_w & (1 << bit_w) ) {
|
|
|
|
c3_w sot_w = han_u->sot_w[inx_w];
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// this slot contains a node, so recurse into that node.
|
|
|
|
//
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_node(sot_w)) ) {
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod recurse\r\n", pre);
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
hav_v = _ch_some_add(hav_v, lef_w, rem_w, kev, use_w);
|
2014-11-06 03:20:01 +03:00
|
|
|
han_u->sot_w[inx_w] = u3h_node_to_slot(hav_v);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
return han_u;
|
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
// this slot contains just one key-value pair
|
|
|
|
//
|
2014-09-05 23:55:16 +04:00
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
u3_noun kov = u3h_slot_to_noun(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// the key is the same, so replace the value
|
|
|
|
//
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( c3y == u3r_sing(u3h(kev), u3h(kov)) ) {
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod replace\r\n", pre);
|
2017-11-04 07:04:24 +03:00
|
|
|
u3m_p("nod kev", kev);
|
|
|
|
u3m_p("nod kov", kov);
|
2014-11-06 03:20:01 +03:00
|
|
|
u3a_lose(kov);
|
|
|
|
han_u->sot_w[inx_w] = u3h_noun_to_slot(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
return han_u;
|
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
// the hash is the same, but the keys are different,
|
2017-11-03 03:47:38 +03:00
|
|
|
// so create a new bucket or node.
|
2017-11-02 04:03:46 +03:00
|
|
|
//
|
2014-09-05 23:55:16 +04:00
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_w rom_w = u3r_mug(u3h(kov)) & ((1 << lef_w) - 1);
|
2014-09-05 23:55:16 +04:00
|
|
|
void* hav_v = _ch_some_new(lef_w);
|
|
|
|
|
|
|
|
// Optimize: need a custom collision create.
|
|
|
|
//
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod pre-kev use_w: %d\r\n", pre, *use_w);
|
2017-11-02 04:03:46 +03:00
|
|
|
hav_v = _ch_some_add(hav_v, lef_w, rem_w, kev, use_w);
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod pre-kov use_w: %d\r\n", pre, *use_w);
|
2017-11-02 04:03:46 +03:00
|
|
|
hav_v = _ch_some_add(hav_v, lef_w, rom_w, kov, use_w);
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod post-kev use_w: %d\r\n", pre, *use_w);
|
2017-11-03 03:47:38 +03:00
|
|
|
(*use_w)--;
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod post-dec use_w: %d\r\n", pre, *use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
han_u->sot_w[inx_w] = u3h_node_to_slot(hav_v);
|
2014-09-05 23:55:16 +04:00
|
|
|
return han_u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-11-02 04:03:46 +03:00
|
|
|
// nothing was at this slot.
|
2014-11-06 03:20:01 +03:00
|
|
|
// Optimize: use u3a_wealloc.
|
2014-09-05 23:55:16 +04:00
|
|
|
//
|
2017-11-02 04:03:46 +03:00
|
|
|
c3_w len_w = _ch_popcount(map_w);
|
2017-11-04 03:03:53 +03:00
|
|
|
u3h_node* nah_u = u3a_walloc(c3_wiseof(u3h_node) +
|
2017-11-02 04:03:46 +03:00
|
|
|
((len_w + 1) * c3_wiseof(u3h_slot)));
|
2014-09-05 23:55:16 +04:00
|
|
|
nah_u->map_w = han_u->map_w | (1 << bit_w);
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod len_w %d -> %d\r\n", pre, len_w, len_w + 1);
|
2017-11-04 03:03:53 +03:00
|
|
|
|
2014-09-05 23:55:16 +04:00
|
|
|
for ( i_w = 0; i_w < inx_w; i_w++ ) {
|
2017-11-04 03:03:53 +03:00
|
|
|
nah_u->sot_w[i_w] = han_u->sot_w[i_w];
|
2017-11-04 23:53:21 +03:00
|
|
|
if ( _(u3h_slot_is_noun(nah_u->sot_w[i_w])) ) {
|
|
|
|
fprintf(stderr, "%snod sot_w[%d]: {%d: %d}\r\n", pre,
|
|
|
|
i_w, u3h(u3h_slot_to_noun(nah_u->sot_w[i_w])),
|
|
|
|
u3t(u3h_slot_to_noun(nah_u->sot_w[i_w])));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%snod sot_w[%d]: <node>\r\n", pre, i_w);
|
|
|
|
}
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2017-11-04 03:03:53 +03:00
|
|
|
nah_u->sot_w[inx_w] = u3h_noun_to_slot(kev);
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod sot_w[%d]: {%d: %d} (inx_w)\r\n", pre,
|
|
|
|
inx_w, u3h(u3h_slot_to_noun(nah_u->sot_w[inx_w])),
|
|
|
|
u3t(u3h_slot_to_noun(nah_u->sot_w[inx_w])));
|
2017-11-04 03:03:53 +03:00
|
|
|
|
2014-09-05 23:55:16 +04:00
|
|
|
for ( i_w = inx_w; i_w < len_w; i_w++ ) {
|
|
|
|
nah_u->sot_w[i_w + 1] = han_u->sot_w[i_w];
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod sot_w[%d]: {%d: %d}\r\n", pre,
|
|
|
|
i_w + 1, u3h(u3h_slot_to_noun(nah_u->sot_w[i_w + 1])),
|
|
|
|
u3t(u3h_slot_to_noun(nah_u->sot_w[i_w + 1])));
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2017-11-04 07:04:24 +03:00
|
|
|
nah_u->arm_w = han_u->arm_w;
|
|
|
|
|
2014-11-25 01:41:47 +03:00
|
|
|
u3a_wfree(han_u);
|
2017-11-04 03:03:53 +03:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
*use_w += 1;
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "%snod post-inc use_w: %d\r\n", pre, *use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
return nah_u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_some_new(): create node or bucket.
|
|
|
|
*/
|
|
|
|
static void*
|
|
|
|
_ch_some_new(c3_w lef_w)
|
|
|
|
{
|
|
|
|
if ( 0 == lef_w ) {
|
|
|
|
return _ch_buck_new();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return _ch_node_new();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_some_add(): add to node or bucket.
|
|
|
|
*/
|
|
|
|
static void*
|
2017-11-02 04:03:46 +03:00
|
|
|
_ch_some_add(void* han_v, c3_w lef_w, c3_w rem_w, u3_noun kev, c3_w *use_w)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
if ( 0 == lef_w ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
return _ch_buck_add((u3h_buck*)han_v, kev, use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
else return _ch_node_add((u3h_node*)han_v, lef_w, rem_w, kev, use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2017-11-04 19:41:45 +03:00
|
|
|
/* _ch_print(): print hashtable.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_ch_print_table(u3h_root* har_u)
|
|
|
|
{
|
|
|
|
u3h_slot sot_w;
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < 64; i_w++ ) {
|
|
|
|
sot_w = har_u->sot_w[i_w];
|
|
|
|
if ( _(u3h_slot_is_null(sot_w)) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun elm = u3h_slot_to_noun(har_u->sot_w[i_w]);
|
|
|
|
fprintf(stderr, "sot_w[%d]: {%d: %d}\r\n", i_w, u3h(elm), u3t(elm));
|
|
|
|
}
|
|
|
|
else if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
fprintf(stderr, "sot_w[%d]: <node>\r\n", i_w);
|
|
|
|
_ch_print_node(u3h_slot_to_node(sot_w), 25);
|
|
|
|
fprintf(stderr, "sot_w[%d]: </node>\r\n", i_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_print_node(): print a node.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_ch_print_node(u3h_node* han_u, c3_w lef_w)
|
|
|
|
{
|
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
c3_w i_w;
|
2017-11-04 23:53:21 +03:00
|
|
|
c3_c* pre = _ch_pre(lef_w);
|
2017-11-04 19:41:45 +03:00
|
|
|
|
|
|
|
lef_w -= 5;
|
2017-11-04 23:53:21 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "%snode @%08x\r\n", pre, han_u);
|
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
2017-11-04 19:41:45 +03:00
|
|
|
fprintf(stderr, "%s<bucket/>\r\n", pre);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < len_w; i_w++ ) {
|
|
|
|
c3_w sot_w = han_u->sot_w[i_w];
|
|
|
|
|
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
|
|
|
|
|
|
|
fprintf(stderr, "%snode[%d]: {%d: %d}\r\n", pre, i_w, u3h(kev), u3t(kev));
|
|
|
|
}
|
|
|
|
else if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
_ch_print_node(u3h_slot_to_node(sot_w), lef_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 23:53:21 +03:00
|
|
|
/* _ch_pre(): get printing whitepsace prefix based on recursion depth.
|
|
|
|
*/
|
|
|
|
static c3_c*
|
|
|
|
_ch_pre(c3_w lef_w)
|
|
|
|
{
|
|
|
|
if ( 25 == lef_w ) { return " "; }
|
|
|
|
else if ( 20 == lef_w ) { return " "; }
|
|
|
|
else if ( 15 == lef_w ) { return " "; }
|
|
|
|
else if ( 10 == lef_w ) { return " "; }
|
|
|
|
else if ( 5 == lef_w ) { return " "; }
|
|
|
|
else { return " "; }
|
|
|
|
}
|
2017-11-04 19:41:45 +03:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
/* u3h_put(): insert in hashtable.
|
2014-09-07 02:39:28 +04:00
|
|
|
**
|
|
|
|
** `key` is RETAINED; `val` is transferred.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_put(u3p(u3h_root) har_p, u3_noun key, u3_noun val)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2017-11-02 04:03:46 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2014-11-04 04:02:55 +03:00
|
|
|
u3_noun kev = u3nc(u3k(key), val);
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_w mug_w = u3r_mug(key);
|
2017-11-02 04:03:46 +03:00
|
|
|
c3_w inx_w = (mug_w >> 25); // 6 bits
|
|
|
|
c3_w rem_w = (mug_w & ((1 << 25) - 1)); // TODO: macro
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w sot_w = har_u->sot_w[inx_w];
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-04 07:04:24 +03:00
|
|
|
u3m_p("put", kev);
|
2017-11-04 19:41:45 +03:00
|
|
|
fprintf(stderr, "inx_w: %d\r\n", inx_w);
|
|
|
|
_ch_print_table(har_u);
|
2017-11-04 07:04:24 +03:00
|
|
|
|
2017-11-03 01:39:57 +03:00
|
|
|
// nothing stored for this 6-bit prefix
|
2017-11-02 04:03:46 +03:00
|
|
|
//
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_null(sot_w)) ) {
|
|
|
|
har_u->sot_w[inx_w] = u3h_noun_to_slot(kev);
|
2017-11-03 01:39:57 +03:00
|
|
|
har_u->use_w++;
|
|
|
|
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "post-nul use_w: %d\r\n", har_u->use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_node* han_u;
|
2017-11-02 04:03:46 +03:00
|
|
|
c3_w *use_w = &(har_u->use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
// one key-value pair for this prefix
|
|
|
|
//
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kov = u3h_slot_to_noun(sot_w);
|
|
|
|
c3_w rom_w = u3r_mug(u3h(kov)) & ((1 << 25) - 1);
|
2017-11-04 03:03:53 +03:00
|
|
|
|
2017-11-04 23:53:21 +03:00
|
|
|
u3m_p("put kov", kov);
|
|
|
|
u3m_p("put kev", kev);
|
2017-11-04 07:04:24 +03:00
|
|
|
|
2014-09-05 23:55:16 +04:00
|
|
|
han_u = _ch_node_new();
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: pre-kev use_w: %d\r\n", har_u->use_w);
|
2017-11-02 04:03:46 +03:00
|
|
|
han_u = _ch_node_add(han_u, 25, rem_w, kev, use_w);
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: pre-kov use_w: %d\r\n", har_u->use_w);
|
2017-11-02 04:03:46 +03:00
|
|
|
han_u = _ch_node_add(han_u, 25, rom_w, kov, use_w);
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: post-kov use_w: %d\r\n", har_u->use_w);
|
2017-11-03 03:47:38 +03:00
|
|
|
(*use_w)--;
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: post-dec use_w: %d\r\n", har_u->use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
// more than one key-value pair for this prefix; use a node
|
|
|
|
//
|
2014-09-05 23:55:16 +04:00
|
|
|
else {
|
2017-11-02 04:03:46 +03:00
|
|
|
han_u = _ch_node_add(u3h_slot_to_node(sot_w), 25, rem_w, kev, use_w);
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: single use_w: %d\r\n", har_u->use_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
har_u->sot_w[inx_w] = u3h_node_to_slot(han_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2017-11-03 01:39:57 +03:00
|
|
|
|
|
|
|
if ( har_u->clk_w > 0 ) {
|
|
|
|
u3h_trim_to(har_p, har_u->clk_w);
|
|
|
|
}
|
2017-11-04 07:04:24 +03:00
|
|
|
fprintf(stderr, "put: final use_w: %d\r\n", har_u->use_w);
|
2017-11-04 19:41:45 +03:00
|
|
|
|
|
|
|
_ch_print_table(har_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
/* u3h_trim_to(): trim to n key-value pairs
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3h_trim_to(u3p(u3h_root) har_p, c3_w n_w)
|
|
|
|
{
|
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
|
|
|
while ( har_u->use_w > n_w ) {
|
|
|
|
_ch_trim_one(har_u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_trim_one(): trim off one key-value pair
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_ch_trim_one(u3h_root *har_u)
|
|
|
|
{
|
|
|
|
u3h_slot root_sot_w = har_u->sot_w[har_u->arm_w];
|
|
|
|
|
|
|
|
c3_assert(har_u->use_w > 0);
|
|
|
|
|
|
|
|
while ( 1 ) {
|
|
|
|
|
|
|
|
if ( _(u3h_slot_is_null(root_sot_w)) ) {
|
|
|
|
// next
|
|
|
|
}
|
|
|
|
else if ( _(u3h_slot_is_node(root_sot_w)) ) {
|
|
|
|
c3_o trimmed = _ch_trim_one_some(&root_sot_w, 25);
|
|
|
|
if ( _(trimmed) ) {
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "trimmed: c3y\r\n");
|
2017-11-02 04:03:46 +03:00
|
|
|
har_u->use_w--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// next
|
|
|
|
}
|
|
|
|
else if ( _(u3h_slot_is_warm(root_sot_w)) ) {
|
|
|
|
har_u->sot_w[har_u->arm_w] = u3h_noun_be_cold(har_u->sot_w[har_u->arm_w]);
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
else {
|
|
|
|
c3_assert(_(u3h_slot_is_noun(root_sot_w)));
|
|
|
|
|
|
|
|
u3_noun kev = u3h_slot_to_noun(root_sot_w);
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "removing sot_w[%d]: {%d: %d}\r\n", har_u->arm_w, u3h(kev), u3t(kev));
|
2017-11-02 04:03:46 +03:00
|
|
|
u3a_lose(kev);
|
|
|
|
har_u->sot_w[har_u->arm_w] = 0;
|
|
|
|
|
|
|
|
har_u->use_w--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-04 07:04:24 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
har_u->arm_w = (har_u->arm_w + 1) % 64;
|
|
|
|
}
|
|
|
|
while ( _(u3h_slot_is_null(har_u->sot_w[har_u->arm_w])) );
|
2017-11-02 04:03:46 +03:00
|
|
|
root_sot_w = har_u->sot_w[har_u->arm_w];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_trim_one_some(): trim one key-value pair from either a node or a bucket.
|
|
|
|
*/
|
|
|
|
static c3_o
|
|
|
|
_ch_trim_one_some(u3h_slot* hal_w, c3_w lef_w)
|
|
|
|
{
|
2017-11-04 23:53:21 +03:00
|
|
|
c3_c* pre = _ch_pre(lef_w);
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
if ( 0 == lef_w ) {
|
2017-11-04 23:53:21 +03:00
|
|
|
// TODO: _ch_buck_deflate()
|
2017-11-02 04:03:46 +03:00
|
|
|
return _ch_trim_one_buck(hal_w);
|
|
|
|
}
|
|
|
|
else {
|
2017-11-04 23:53:21 +03:00
|
|
|
u3h_slot old_w = *hal_w;
|
|
|
|
|
|
|
|
fprintf(stderr, "%strim_one_some <node>\r\n", pre);
|
|
|
|
_ch_print_node(u3h_slot_to_node(*hal_w), lef_w);
|
|
|
|
fprintf(stderr, "%strim_one_some </node>\r\n", pre);
|
|
|
|
|
|
|
|
c3_o del_o = _ch_trim_one_node(hal_w, lef_w);
|
|
|
|
|
|
|
|
if ( _(del_o) ) {
|
|
|
|
_ch_node_deflate(hal_w, lef_w);
|
|
|
|
c3_assert(old_w != *hal_w);
|
|
|
|
|
|
|
|
u3_noun kev = u3h_slot_to_noun(*hal_w);
|
|
|
|
fprintf(stderr, "%strim_one_some deflated: {%d: %d}\r\n", pre, u3h(kev), u3t(kev));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%strim_one_some did not trim node\r\n", pre);
|
|
|
|
}
|
|
|
|
return del_o;
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_trim_one_buck(): trim one key-value pair from a bucket.
|
|
|
|
*/
|
|
|
|
static c3_o
|
|
|
|
_ch_trim_one_buck(u3h_slot* hal_w)
|
|
|
|
{
|
|
|
|
u3h_buck* hab_u = (u3h_buck*)u3h_slot_to_node(*hal_w);
|
|
|
|
u3h_slot sot_w = hab_u->sot_w[hab_u->arm_w];
|
|
|
|
|
|
|
|
c3_assert(hab_u->len_w != 1);
|
|
|
|
|
|
|
|
// instead of assigning a bucket with only one element,
|
|
|
|
// assign a single key-value pair as a slot.
|
|
|
|
//
|
|
|
|
if ( hab_u->len_w == 2 ) {
|
|
|
|
u3h_slot fir_w = hab_u->sot_w[0];
|
|
|
|
u3h_slot sec_w = hab_u->sot_w[1];
|
|
|
|
|
|
|
|
if ( _(u3h_slot_is_warm(fir_w)) ) {
|
|
|
|
if ( _(u3h_slot_is_warm(sec_w)) ) {
|
|
|
|
hab_u->sot_w[0] = u3h_noun_be_cold(fir_w);
|
|
|
|
hab_u->sot_w[1] = u3h_noun_be_cold(sec_w);
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3a_lose(u3h_slot_to_noun(sec_w));
|
|
|
|
*hal_w = u3h_noun_be_cold(u3h_slot_to_noun(fir_w));
|
|
|
|
return c3y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3a_lose(u3h_slot_to_noun(fir_w));
|
|
|
|
*hal_w = u3h_slot_to_noun(sec_w);
|
|
|
|
return c3y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while ( hab_u->arm_w < hab_u->len_w ) {
|
|
|
|
sot_w = hab_u->sot_w[hab_u->arm_w];
|
|
|
|
|
|
|
|
if ( _(u3h_slot_is_warm(sot_w)) ) {
|
|
|
|
hab_u->sot_w[hab_u->arm_w] = u3h_noun_be_cold(sot_w);
|
|
|
|
hab_u->arm_w++;
|
|
|
|
// next
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w i_w;
|
|
|
|
c3_w len_w = hab_u->len_w;
|
|
|
|
u3h_buck* bah_u = u3a_walloc(c3_wiseof(u3h_buck) +
|
|
|
|
(len_w - 1) * c3_wiseof(u3h_slot));
|
|
|
|
|
|
|
|
bah_u->len_w = len_w - 1;
|
|
|
|
bah_u->arm_w = hab_u->arm_w;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->arm_w; i_w++ ) {
|
|
|
|
bah_u->sot_w[i_w] = hab_u->sot_w[i_w];
|
|
|
|
}
|
|
|
|
|
|
|
|
u3a_lose(u3h_slot_to_noun(hab_u->sot_w[hab_u->arm_w]));
|
|
|
|
|
|
|
|
for ( i_w = hab_u->arm_w; i_w < bah_u->len_w; i_w++ ) {
|
|
|
|
bah_u->sot_w[i_w] = hab_u->sot_w[i_w + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
*hal_w = u3h_node_to_slot(bah_u);
|
|
|
|
return c3y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hab_u->arm_w = 0;
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_trim_one_node(): trim one key-value pair from a node.
|
|
|
|
*/
|
|
|
|
static c3_o
|
|
|
|
_ch_trim_one_node(u3h_slot* hal_w, c3_w lef_w)
|
|
|
|
{
|
|
|
|
u3h_node* han_u = (u3h_node*)u3h_slot_to_node(*hal_w);
|
|
|
|
u3h_slot sot_w = han_u->sot_w[han_u->arm_w];
|
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
|
|
|
|
c3_assert(len_w != 1);
|
|
|
|
|
2017-11-04 23:53:21 +03:00
|
|
|
fprintf(stderr, "trim_one_node arm_w: %d\r\n", han_u->arm_w);
|
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
while (han_u->arm_w < len_w) {
|
|
|
|
sot_w = han_u->sot_w[han_u->arm_w];
|
2017-11-02 04:03:46 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
if ( _(_ch_trim_one_some(&sot_w, lef_w - 5)) ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
return c3y;
|
|
|
|
}
|
2017-11-04 03:03:53 +03:00
|
|
|
// next
|
2017-11-03 03:47:38 +03:00
|
|
|
}
|
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
else if ( _(u3h_slot_is_warm(sot_w)) ) {
|
|
|
|
han_u->sot_w[han_u->arm_w] = u3h_noun_be_cold(sot_w);
|
|
|
|
han_u->arm_w++;
|
|
|
|
// next
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
2017-11-04 03:03:53 +03:00
|
|
|
else {
|
|
|
|
c3_w bit_w, i_w, inx_w;
|
2017-11-03 03:47:38 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
u3h_node* nah_u = u3a_walloc(c3_wiseof(u3h_node) +
|
|
|
|
((len_w - 1) * c3_wiseof(u3h_slot)));
|
2017-11-03 03:47:38 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
bit_w = han_u->arm_w;
|
|
|
|
nah_u->map_w = han_u->map_w & ~(1 << bit_w);
|
|
|
|
inx_w = _ch_popcount(nah_u->map_w & ((1 << bit_w) - 1));
|
|
|
|
nah_u->arm_w = han_u->arm_w;
|
2017-11-02 04:03:46 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
for ( i_w = 0; i_w < inx_w; i_w++ ) {
|
|
|
|
nah_u->sot_w[i_w] = han_u->sot_w[i_w];
|
|
|
|
}
|
2017-11-02 04:03:46 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
u3a_lose(u3h_slot_to_noun(han_u->sot_w[inx_w]));
|
2017-11-02 04:03:46 +03:00
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
for ( i_w = inx_w; i_w < len_w - 1; i_w++ ) {
|
|
|
|
nah_u->sot_w[i_w] = han_u->sot_w[i_w + 1];
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
|
|
|
|
2017-11-04 03:03:53 +03:00
|
|
|
*hal_w = u3h_node_to_slot(nah_u);
|
|
|
|
return c3y;
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
2017-11-04 03:03:53 +03:00
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
2017-11-04 03:03:53 +03:00
|
|
|
han_u->arm_w = 0;
|
|
|
|
return c3n;
|
2017-11-02 04:03:46 +03:00
|
|
|
}
|
|
|
|
|
2017-11-04 23:53:21 +03:00
|
|
|
/* _ch_node_deflate(); convert singleton node to key-value pair.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_ch_node_deflate(u3h_slot* sot_w, c3_w lef_w)
|
|
|
|
{
|
|
|
|
u3h_node* han_u = (u3h_node*)u3h_slot_to_node(*sot_w);
|
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
c3_c* pre = _ch_pre(lef_w);
|
|
|
|
|
|
|
|
if ( 1 == len_w ) {
|
|
|
|
fprintf(stderr, "%snode_deflate: deflating\r\n", pre);
|
|
|
|
|
|
|
|
if ( _(u3h_slot_is_node(han_u->sot_w[0])) ) {
|
|
|
|
fprintf(stderr, "%snode_deflate: recursing\r\n", pre);
|
|
|
|
_ch_node_deflate(&han_u->sot_w[0], lef_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
// bump refcount before freeing node to make sure kev
|
|
|
|
// doesn't get freed.
|
|
|
|
//
|
|
|
|
u3_noun kev = u3k(u3h_slot_to_noun(han_u->sot_w[0]));
|
|
|
|
|
|
|
|
_ch_free_node(han_u, lef_w);
|
|
|
|
|
|
|
|
*sot_w = u3h_noun_to_slot(kev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:32:07 +04:00
|
|
|
/* _ch_buck_hum(): read in bucket.
|
|
|
|
*/
|
|
|
|
static c3_o
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_buck_hum(u3h_buck* hab_u, c3_w mug_w)
|
2014-09-25 22:32:07 +04:00
|
|
|
{
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
if ( mug_w == u3r_mug(u3h(u3h_slot_to_noun(hab_u->sot_w[i_w]))) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3y;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_node_hum(): read in node.
|
|
|
|
*/
|
|
|
|
static c3_o
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_node_hum(u3h_node* han_u, c3_w lef_w, c3_w rem_w, c3_w mug_w)
|
2014-09-25 22:32:07 +04:00
|
|
|
{
|
|
|
|
c3_w bit_w, map_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
bit_w = (rem_w >> lef_w);
|
|
|
|
rem_w = (rem_w & ((1 << lef_w) - 1));
|
|
|
|
map_w = han_u->map_w;
|
|
|
|
|
|
|
|
if ( !(map_w & (1 << bit_w)) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w inx_w = _ch_popcount(map_w & ((1 << bit_w) - 1));
|
|
|
|
c3_w sot_w = han_u->sot_w[inx_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-25 22:32:07 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( mug_w == u3r_mug(u3h(kev)) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3y;
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-09-25 22:32:07 +04:00
|
|
|
else {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-09-25 22:32:07 +04:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
|
|
|
return _ch_buck_hum(hav_v, mug_w);
|
|
|
|
}
|
|
|
|
else return _ch_node_hum(hav_v, lef_w, rem_w, mug_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
/* u3h_hum(): check presence in hashtable.
|
2014-09-25 22:32:07 +04:00
|
|
|
**
|
|
|
|
** `key` is RETAINED.
|
|
|
|
*/
|
|
|
|
c3_o
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_hum(u3p(u3h_root) har_p, c3_w mug_w)
|
2014-09-25 22:32:07 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w inx_w = (mug_w >> 25);
|
|
|
|
c3_w rem_w = (mug_w & ((1 << 25) - 1));
|
|
|
|
c3_w sot_w = har_u->sot_w[inx_w];
|
2014-09-25 22:32:07 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_null(sot_w)) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-25 22:32:07 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( mug_w == u3r_mug(u3h(kev)) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3y;
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-09-25 22:32:07 +04:00
|
|
|
else {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-09-25 22:32:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-09-25 22:32:07 +04:00
|
|
|
|
|
|
|
return _ch_node_hum(han_u, 25, rem_w, mug_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:06:08 +03:00
|
|
|
/* _ch_buck_git(): read in bucket.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_weak
|
2014-12-01 03:06:08 +03:00
|
|
|
_ch_buck_git(u3h_buck* hab_u, u3_noun key)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
u3_noun kev = u3h_slot_to_noun(hab_u->sot_w[i_w]);
|
|
|
|
if ( _(u3r_sing(key, u3h(kev))) ) {
|
|
|
|
return u3t(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-12-01 03:06:08 +03:00
|
|
|
/* _ch_node_git(): read in node.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_weak
|
2014-12-01 03:06:08 +03:00
|
|
|
_ch_node_git(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
c3_w bit_w, map_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
bit_w = (rem_w >> lef_w);
|
|
|
|
rem_w = (rem_w & ((1 << lef_w) - 1));
|
|
|
|
map_w = han_u->map_w;
|
|
|
|
|
|
|
|
if ( !(map_w & (1 << bit_w)) ) {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w inx_w = _ch_popcount(map_w & ((1 << bit_w) - 1));
|
|
|
|
c3_w sot_w = han_u->sot_w[inx_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3r_sing(key, u3h(kev))) ) {
|
2014-12-01 03:06:08 +03:00
|
|
|
return u3t(kev);
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-09-05 23:55:16 +04:00
|
|
|
else {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
2014-12-01 03:06:08 +03:00
|
|
|
return _ch_buck_git(hav_v, key);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-12-01 03:06:08 +03:00
|
|
|
else return _ch_node_git(hav_v, lef_w, rem_w, key);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:06:08 +03:00
|
|
|
/* u3h_git(): read from hashtable.
|
2014-09-07 02:39:28 +04:00
|
|
|
**
|
2014-12-01 03:06:08 +03:00
|
|
|
** `key` is RETAINED; result is RETAINED.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_weak
|
2014-12-01 03:06:08 +03:00
|
|
|
u3h_git(u3p(u3h_root) har_p, u3_noun key)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2017-11-02 04:03:46 +03:00
|
|
|
c3_w mug_w = u3r_mug(key);
|
|
|
|
c3_w inx_w = (mug_w >> 25);
|
|
|
|
c3_w rem_w = (mug_w & ((1 << 25) - 1));
|
|
|
|
c3_w sot_w = har_u->sot_w[inx_w];
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_null(sot_w)) ) {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3r_sing(key, u3h(kev))) ) {
|
|
|
|
har_u->sot_w[inx_w] = u3h_noun_be_warm(sot_w);
|
2014-12-01 03:06:08 +03:00
|
|
|
return u3t(kev);
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-09-05 23:55:16 +04:00
|
|
|
else {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-12-01 03:06:08 +03:00
|
|
|
return _ch_node_git(han_u, 25, rem_w, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:03:46 +03:00
|
|
|
/* u3h_get(): read from hashtable, incrementing refcount.
|
2014-12-01 03:06:08 +03:00
|
|
|
**
|
|
|
|
** `key` is RETAINED; result is PRODUCED.
|
|
|
|
*/
|
|
|
|
u3_weak
|
|
|
|
u3h_get(u3p(u3h_root) har_p, u3_noun key)
|
|
|
|
{
|
|
|
|
u3_noun pro = u3h_git(har_p, key);
|
|
|
|
|
|
|
|
if ( u3_none != pro ) {
|
|
|
|
u3a_gain(pro);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-12-01 03:06:08 +03:00
|
|
|
return pro;
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-10-09 02:16:24 +04:00
|
|
|
/* _ch_buck_gut(): read in bucket, unifying key nouns.
|
|
|
|
*/
|
|
|
|
static u3_weak
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_buck_gut(u3h_buck* hab_u, u3_noun key)
|
2014-10-09 02:16:24 +04:00
|
|
|
{
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
u3_noun kev = u3h_slot_to_noun(hab_u->sot_w[i_w]);
|
|
|
|
if ( _(u3r_sung(key, u3h(kev))) ) {
|
|
|
|
return u3a_gain(u3t(kev));
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_node_gut(): read in node, unifying key nouns.
|
|
|
|
*/
|
|
|
|
static u3_weak
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_node_gut(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key)
|
2014-10-09 02:16:24 +04:00
|
|
|
{
|
|
|
|
c3_w bit_w, map_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
bit_w = (rem_w >> lef_w);
|
|
|
|
rem_w = (rem_w & ((1 << lef_w) - 1));
|
|
|
|
map_w = han_u->map_w;
|
|
|
|
|
|
|
|
if ( !(map_w & (1 << bit_w)) ) {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w inx_w = _ch_popcount(map_w & ((1 << bit_w) - 1));
|
|
|
|
c3_w sot_w = han_u->sot_w[inx_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-09 02:16:24 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3r_sung(key, u3h(kev))) ) {
|
|
|
|
return u3a_gain(u3t(kev));
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-10-09 02:16:24 +04:00
|
|
|
else {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-10-09 02:16:24 +04:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
|
|
|
return _ch_buck_gut(hav_v, key);
|
|
|
|
}
|
|
|
|
else return _ch_node_gut(hav_v, lef_w, rem_w, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
/* u3h_gut(): read from hashtable, unifying key nouns.
|
2014-10-09 02:16:24 +04:00
|
|
|
**
|
|
|
|
** `key` is RETAINED.
|
|
|
|
*/
|
|
|
|
u3_weak
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_gut(u3p(u3h_root) har_p, u3_noun key)
|
2014-10-09 02:16:24 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
|
|
|
c3_w mug_w = u3r_mug(key);
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w inx_w = (mug_w >> 25);
|
|
|
|
c3_w rem_w = (mug_w & ((1 << 25) - 1));
|
|
|
|
c3_w sot_w = har_u->sot_w[inx_w];
|
2014-10-09 02:16:24 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_null(sot_w)) ) {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-09 02:16:24 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3r_sung(key, u3h(kev))) ) {
|
|
|
|
har_u->sot_w[inx_w] = u3h_noun_be_warm(sot_w);
|
|
|
|
return u3a_gain(u3t(kev));
|
2017-11-04 03:03:53 +03:00
|
|
|
}
|
2014-10-09 02:16:24 +04:00
|
|
|
else {
|
2014-11-06 02:36:30 +03:00
|
|
|
return u3_none;
|
2014-10-09 02:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-10-09 02:16:24 +04:00
|
|
|
|
|
|
|
return _ch_node_gut(han_u, 25, rem_w, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 23:55:16 +04:00
|
|
|
/* _ch_free_buck(): free bucket
|
|
|
|
*/
|
|
|
|
static void
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_free_buck(u3h_buck* hab_u)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2017-11-04 03:03:53 +03:00
|
|
|
c3_w i_w;
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
u3a_lose(u3h_slot_to_noun(hab_u->sot_w[i_w]));
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-11-25 01:41:47 +03:00
|
|
|
u3a_wfree(hab_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_free_node(): free node.
|
|
|
|
*/
|
|
|
|
static void
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_free_node(u3h_node* han_u, c3_w lef_w)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < len_w; i_w++ ) {
|
|
|
|
c3_w sot_w = han_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
u3a_lose(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
|
|
|
_ch_free_buck(hav_v);
|
|
|
|
} else {
|
|
|
|
_ch_free_node(hav_v, lef_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 01:41:47 +03:00
|
|
|
u3a_wfree(han_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
/* u3h_free(): free hashtable.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_free(u3p(u3h_root) har_p)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w i_w;
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < 64; i_w++ ) {
|
|
|
|
c3_w sot_w = har_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
u3a_lose(kev);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-09-05 23:55:16 +04:00
|
|
|
|
|
|
|
_ch_free_node(han_u, 25);
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 01:41:47 +03:00
|
|
|
u3a_wfree(har_u);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-10-31 00:40:05 +03:00
|
|
|
/* _ch_walk_buck(): walk bucket for gc.
|
|
|
|
*/
|
|
|
|
static void
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun))
|
2014-10-31 00:40:05 +03:00
|
|
|
{
|
2017-11-04 03:03:53 +03:00
|
|
|
c3_w i_w;
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
fun_f(u3h_slot_to_noun(hab_u->sot_w[i_w]));
|
2014-10-31 00:40:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_walk_node(): walk node for gc.
|
|
|
|
*/
|
|
|
|
static void
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun))
|
2014-10-31 00:40:05 +03:00
|
|
|
{
|
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < len_w; i_w++ ) {
|
|
|
|
c3_w sot_w = han_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
fun_f(kev);
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
|
|
|
_ch_walk_buck(hav_v, fun_f);
|
|
|
|
} else {
|
|
|
|
_ch_walk_node(hav_v, lef_w, fun_f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
/* u3h_walk(): walk hashtable for gc.
|
2014-10-31 00:40:05 +03:00
|
|
|
*/
|
|
|
|
void
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun))
|
2014-10-31 00:40:05 +03:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w i_w;
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < 64; i_w++ ) {
|
|
|
|
c3_w sot_w = har_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
fun_f(kev);
|
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-10-31 00:40:05 +03:00
|
|
|
|
|
|
|
_ch_walk_node(han_u, 25, fun_f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-09 06:20:57 +04:00
|
|
|
/* _ch_mark_buck(): mark bucket for gc.
|
|
|
|
*/
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_mark_buck(u3h_buck* hab_u)
|
2014-10-09 06:20:57 +04:00
|
|
|
{
|
2015-05-09 03:42:09 +03:00
|
|
|
c3_w tot_w = 0;
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w i_w;
|
2014-10-09 06:20:57 +04:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
2017-11-02 04:03:46 +03:00
|
|
|
tot_w += u3a_mark_noun(u3h_slot_to_noun(hab_u->sot_w[i_w]));
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += u3a_mark_ptr(hab_u);
|
|
|
|
|
|
|
|
return tot_w;
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ch_mark_node(): mark node for gc.
|
|
|
|
*/
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w
|
2014-11-06 03:20:01 +03:00
|
|
|
_ch_mark_node(u3h_node* han_u, c3_w lef_w)
|
2014-10-09 06:20:57 +04:00
|
|
|
{
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w tot_w = 0;
|
2014-10-09 06:20:57 +04:00
|
|
|
c3_w len_w = _ch_popcount(han_u->map_w);
|
|
|
|
c3_w i_w;
|
|
|
|
|
|
|
|
lef_w -= 5;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < len_w; i_w++ ) {
|
|
|
|
c3_w sot_w = han_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-09 06:20:57 +04:00
|
|
|
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += u3a_mark_noun(kev);
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
void* hav_v = u3h_slot_to_node(sot_w);
|
2014-10-09 06:20:57 +04:00
|
|
|
|
|
|
|
if ( 0 == lef_w ) {
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += _ch_mark_buck(hav_v);
|
2014-10-09 06:20:57 +04:00
|
|
|
} else {
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += _ch_mark_node(hav_v, lef_w);
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-08 02:16:54 +03:00
|
|
|
|
|
|
|
tot_w += u3a_mark_ptr(han_u);
|
|
|
|
|
|
|
|
return tot_w;
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
/* u3h_mark(): mark hashtable for gc.
|
2014-10-09 06:20:57 +04:00
|
|
|
*/
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_mark(u3p(u3h_root) har_p)
|
2014-10-09 06:20:57 +04:00
|
|
|
{
|
2015-05-08 02:16:54 +03:00
|
|
|
c3_w tot_w = 0;
|
2014-11-06 03:20:01 +03:00
|
|
|
u3h_root* har_u = u3to(u3h_root, har_p);
|
2014-11-04 04:02:55 +03:00
|
|
|
c3_w i_w;
|
2014-10-09 06:20:57 +04:00
|
|
|
|
|
|
|
for ( i_w = 0; i_w < 64; i_w++ ) {
|
|
|
|
c3_w sot_w = har_u->sot_w[i_w];
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( _(u3h_slot_is_noun(sot_w)) ) {
|
|
|
|
u3_noun kev = u3h_slot_to_noun(sot_w);
|
2014-10-09 06:20:57 +04:00
|
|
|
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += u3a_mark_noun(kev);
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if ( _(u3h_slot_is_node(sot_w)) ) {
|
|
|
|
u3h_node* han_u = u3h_slot_to_node(sot_w);
|
2014-10-09 06:20:57 +04:00
|
|
|
|
2015-05-08 02:16:54 +03:00
|
|
|
tot_w += _ch_mark_node(han_u, 25);
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-08 02:16:54 +03:00
|
|
|
|
|
|
|
tot_w += u3a_mark_ptr(har_u);
|
|
|
|
|
|
|
|
return tot_w;
|
2014-10-09 06:20:57 +04:00
|
|
|
}
|