Style cleanups.

This commit is contained in:
C. Guy Yarvin 2014-05-07 11:31:54 -07:00
parent af465d30d5
commit 44dfc2118a

View File

@ -5,21 +5,29 @@
#include "all.h"
#include <bitmapped_patricia_tree.h>
struct u2_nair {
u2_noun key;
u2_noun val;
};
/* structures
*/
/* u2_nair: bucket node.
*/
struct u2_nair {
u2_noun key;
u2_noun val;
};
struct u2_buck {
c3_w con_w;
struct u2_nair* sto_u;
};
/* u2_buck: realloced bucket.
*/
struct u2_buck {
c3_w con_w;
struct u2_nair* sto_u;
};
struct u2_nash {
bpt_t sto;
};
/* u2_nash: wrapper around Patricia trie.
*/
struct u2_nash {
bpt_t sto;
};
void u2_na_dump(struct u2_nash* nash);
void u2_na_dump(struct u2_nash* nas_u);
/* u2_na_make(): create a new nounhash-table.
**
@ -34,9 +42,9 @@ u2_na_make()
}
/* u2_na_put(): put into nash, replacing.
**/
*/
void
u2_na_put(struct u2_nash* nash, u2_noun key, u2_noun val)
u2_na_put(struct u2_nash* nas_u, u2_noun key, u2_noun val)
{
struct u2_buck* buc_u = 0;
struct u2_nair* nuu_u = 0;
@ -45,22 +53,23 @@ u2_na_put(struct u2_nash* nash, u2_noun key, u2_noun val)
u2_noun tom = u2_mug(key);
if ( !bpt_has_key(nash->sto, tom)) {
if ( !bpt_has_key(nas_u->sto, tom)) {
bpt_t ots;
buc_u = calloc(1, sizeof(*buc_u));
ots = bpt_assoc(nash->sto, tom, buc_u);
bpt_release(nash->sto);
nash->sto = ots;
ots = bpt_assoc(nas_u->sto, tom, buc_u);
bpt_release(nas_u->sto);
nas_u->sto = ots;
#if 0
fprintf(stderr, "[%%nash-sto %p %p]\r\n", nash->sto, tom);
if (!bpt_has_key(nash->sto, tom)) {
fprintf(stderr, "[%%nash-sto %p %p]\r\n", nas_u->sto, tom);
if (!bpt_has_key(nas_u->sto, tom)) {
u2_na_dump(nash);
assert(0);
}
#endif
}
buc_u = bpt_get(nash->sto, tom);
buc_u = bpt_get(nas_u->sto, tom);
if ( 0 == buc_u->con_w ) {
c3_assert(buc_u->sto_u == 0);
@ -93,20 +102,21 @@ u2_na_put(struct u2_nash* nash, u2_noun key, u2_noun val)
#endif
}
/* u2_na_get(): get from a nounhash table
**/
/* u2_na_get(): get from a nounhash table.
*/
u2_weak
u2_na_get(struct u2_nash* nash, u2_noun key)
u2_na_get(struct u2_nash* nas_u, u2_noun key)
{
struct u2_buck* buc_u = 0;
c3_w i;
u2_noun tom = u2_mug(key);
if ( !bpt_has_key(nash->sto, tom) ) {
// fprintf(stderr, "[%%nash-get-none %p %p]\r\n", nash->sto, tom);
if ( !bpt_has_key(nas_u->sto, tom) ) {
// fprintf(stderr, "[%%nash-get-none %p %p]\r\n", nas_u->sto, tom);
return u2_none;
}
buc_u = bpt_get(nash->sto, tom);
buc_u = bpt_get(nas_u->sto, tom);
for(i = 0; i < buc_u->con_w; i++) {
if (u2_sing(buc_u->sto_u[i].key, key) == u2_yes) {
#if 0
@ -119,8 +129,9 @@ u2_na_get(struct u2_nash* nash, u2_noun key)
return u2_none;
}
static
void
/* _na_drop(): deallocate a node.
*/
static void
_na_drop(bpt_key_t x, void* a, void* b)
{
struct u2_buck* buc = a;
@ -128,6 +139,8 @@ _na_drop(bpt_key_t x, void* a, void* b)
free(buc);
}
/* _na_dump(): debugging dump.
*/
void
_na_dump(bpt_key_t x, void* a, void* b)
{
@ -141,18 +154,21 @@ _na_dump(bpt_key_t x, void* a, void* b)
fprintf(stderr, "]\r\n");
}
void u2_na_dump(struct u2_nash* nash)
/* u2_na_dump(): debugging dump.
*/
void u2_na_dump(struct u2_nash* nas_u)
{
if(nash->sto) bpt_for_mappings(nash->sto, _na_dump, 0);
if(nas_u->sto) bpt_for_mappings(nas_u->sto, _na_dump, 0);
}
/* u2_na_take(): destroy a nounhash table
**/
/* u2_na_take(): destroy a nounhash table.
*/
void
u2_na_take(struct u2_nash* nash)
u2_na_take(struct u2_nash* nas_u)
{
bpt_for_mappings(nash->sto, _na_drop, 0);
bpt_release(nash->sto);
free(nash);
bpt_for_mappings(nas_u->sto, _na_drop, 0);
bpt_release(nas_u->sto);
free(nas_u);
// fprintf(stderr, "[%%nash-take %p]\r\n", nash);
}