ur: updates api to consistently use (len, bytes) for vectors

This commit is contained in:
Joe Bryan 2020-09-15 13:50:22 -07:00
parent a353179908
commit 39a82fe66d
6 changed files with 17 additions and 17 deletions

View File

@ -64,7 +64,7 @@ typedef uint8_t ur_bool_t;
** unsafe wrt trailing null bytes, which are invalid
*/
inline uint64_t
ur_met0_bytes_unsafe(uint8_t *byt, uint64_t len)
ur_met0_bytes_unsafe(uint64_t len, uint8_t *byt)
{
uint64_t last = len - 1;
return (last << 3) + ur_met0_8(byt[last]);

View File

@ -174,10 +174,10 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref);
** allocated with system malloc) and trailing null bytes (not allowed).
*/
ur_nref
ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len);
ur_coin_bytes_unsafe(ur_root_t *r, uint64_t len, uint8_t *byt);
ur_nref
ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len);
ur_coin_bytes(ur_root_t *r, uint64_t len, uint8_t *byt);
ur_nref
ur_coin64(ur_root_t *r, uint64_t n);

View File

@ -57,10 +57,10 @@ _cu_atom_to_ref(ur_root_t* rot_u, u3a_atom* vat_u)
c3_assert( len_d );
// NB: this call will accounts for any trailing null bytes
// NB: this call will account for any trailing null bytes
// caused by an overestimate in [len_d]
//
ref = ur_coin_bytes(rot_u, byt_y, len_d);
ref = ur_coin_bytes(rot_u, len_d, byt_y);
} break;
}

View File

@ -1810,13 +1810,13 @@ _test_jam_cue(void)
{
uint8_t inp[33] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
uint8_t res[35] = { 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 };
TEST_CASE("wide", ur_coin_bytes(r, inp, sizeof(inp)));
TEST_CASE("wide", ur_coin_bytes(r, sizeof(inp), inp));
}
{
uint8_t inp[16] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0xa8, 0xab, 0x60, 0xef, 0x2d, 0xd, 0x0, 0x0, 0x80 };
uint8_t res[19] = { 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x50, 0x57, 0xc1, 0xde, 0x5b, 0x1a, 0x0, 0x0, 0x0, 0x1 };
TEST_CASE("date", ur_coin_bytes(r, inp, sizeof(inp)));
TEST_CASE("date", ur_coin_bytes(r, sizeof(inp), inp));
}
ur_root_free(r);

View File

@ -15,7 +15,7 @@
// declarations of inline functions
//
uint64_t
ur_met0_bytes_unsafe(uint8_t *byt, uint64_t len);
ur_met0_bytes_unsafe(uint64_t len, uint8_t *byt);
static void*
_oom(const char* cap, void* v)
@ -543,7 +543,7 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
uint64_t len = r->atoms.lens[idx];
uint8_t *byt = r->atoms.bytes[idx];
m_bit = ur_met0_bytes_unsafe(byt, len);
m_bit = ur_met0_bytes_unsafe(len, byt);
}
switch ( bloq ) {
@ -568,7 +568,7 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
}
static ur_nref
_coin_unsafe(ur_atoms_t *atoms, ur_mug mug, uint8_t *byt, uint64_t len)
_coin_unsafe(ur_atoms_t *atoms, ur_mug mug, uint64_t len, uint8_t *byt)
{
uint64_t fill = atoms->fill;
ur_tag tag = ur_iatom;
@ -606,7 +606,7 @@ _cons_unsafe(ur_cells_t *cells, ur_mug mug, ur_nref hed, ur_nref tal)
}
ur_nref
ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len)
ur_coin_bytes_unsafe(ur_root_t *r, uint64_t len, uint8_t *byt)
{
ur_atoms_t *atoms = &(r->atoms);
ur_dict_t *dict = &(atoms->dict);
@ -641,7 +641,7 @@ ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len)
ur_atoms_grow(atoms);
}
tom = _coin_unsafe(atoms, mug, byt, len);
tom = _coin_unsafe(atoms, mug, len, byt);
bucket->refs[b_fill] = tom;
bucket->fill = 1 + b_fill;
@ -651,7 +651,7 @@ ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len)
}
ur_nref
ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len)
ur_coin_bytes(ur_root_t *r, uint64_t len, uint8_t *byt)
{
// strip trailing zeroes
//
@ -661,7 +661,7 @@ ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len)
// produce a direct atom if possible
//
if ( 62 >= ur_met0_bytes_unsafe(byt, len) ) {
if ( 62 >= ur_met0_bytes_unsafe(len, byt) ) {
uint64_t i, direct = 0;
for ( i = 0; i < len; i++ ) {
@ -674,7 +674,7 @@ ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len)
uint8_t *copy = _oom("coin_bytes", malloc(len));
memcpy(copy, byt, len);
return ur_coin_bytes_unsafe(r, copy, len);
return ur_coin_bytes_unsafe(r, len, copy);
}
}
@ -699,7 +699,7 @@ ur_coin64(ur_root_t *r, uint64_t n)
byt[6] = ur_mask_8(n >> 48);
byt[7] = ur_mask_8(n >> 56);
return ur_coin_bytes_unsafe(r, byt, 8);
return ur_coin_bytes_unsafe(r, 8, byt);
}
}

View File

@ -214,7 +214,7 @@ _cue_next(ur_root_t *r,
len_byt--;
}
*out = ur_coin_bytes_unsafe(r, byt, len_byt);
*out = ur_coin_bytes_unsafe(r, len_byt, byt);
}
ur_dict64_put(r, dict, bits, (uint64_t)*out);