variant with edge length = 16

This commit is contained in:
Alain Zscheile 2022-12-18 05:13:32 +01:00
parent 1615b45d78
commit bf9048443b
2 changed files with 8 additions and 9 deletions

15
y16t.c
View file

@ -7,11 +7,11 @@ static __attribute__((pure))
uint8_t y16t_loc2blk_coords(
const y16t_location_t loc, const uint32_t offset
) {
const uint32_t byteoffset = offset / 4;
const uint8_t shiftval = 2 * (3 - offset % 4);
const uint8_t xres = (loc.x[byteoffset] >> shiftval) & 3;
const uint8_t yres = (loc.y[byteoffset] >> shiftval) & 3;
return (xres << 2) | yres;
const uint32_t byteoffset = offset >> 1;
const uint8_t shiftval = 4 * (1 - offset & 1);
const uint8_t xres = (loc.x[byteoffset] >> shiftval) & 15;
const uint8_t yres = (loc.y[byteoffset] >> shiftval) & 15;
return (xres << 4) | yres;
}
void y16t_lookup(
@ -20,13 +20,12 @@ void y16t_lookup(
const size_t datalen,
const y16t_location_t * loc
) {
// data_endblk is set to the first byte which doesn't constitute a full block
const size_t datalen_blks = datalen / 16;
const size_t datalen_blks = datalen >> 8;
const y16t_location_t loc_ = *loc;
size_t datoffset = ret->datoffset;
for ( ; /* bounds checks */ ret->inpoffset < loc_.xylen && datoffset < datalen_blks; ) {
datoffset = ntohl(data[16 * datoffset + y16t_loc2blk_coords(loc_, ret->inpoffset)]);
datoffset = ntohl(data[(datoffset << 8) | y16t_loc2blk_coords(loc_, ret->inpoffset)]);
ret->inpoffset += 1;
if(0 == datoffset) {
// NULL pointer

2
y16t.h
View file

@ -6,7 +6,7 @@
typedef struct {
uint8_t *x;
uint8_t *y;
// x and y should have the same length, and xylen = bytescount * 4
// x and y should have the same length, and xylen = bytescount * 2
uint32_t xylen;
} y16t_location_t;