restructuring + ensure byte order conversion
This commit is contained in:
parent
5f92902208
commit
3ae7f219e6
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: ISC
|
||||
#include "y16t_hilbert.h"
|
||||
#include "y16t_internal.h"
|
||||
|
||||
// rotate/flip a quadrant appropriately
|
||||
static void y16t_hilbert_rot(uint32_t n, uint32_t *x, uint32_t *y, uint32_t rx, uint32_t ry) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: ISC
|
||||
#include "y16t.h"
|
||||
#include "y16t_hilbert.h"
|
||||
#include "y16t_internal.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -22,6 +22,7 @@ int y16t_idx_lookup(
|
|||
return -EIO;
|
||||
if(fread(result, 4, 1, fh) != 1)
|
||||
return -EIO;
|
||||
*result = ntohl(*result);
|
||||
if(key && fseek(fh, -key, SEEK_CUR) == -1)
|
||||
return -EIO;
|
||||
|
||||
|
@ -35,10 +36,11 @@ int y16t_idx_update(
|
|||
const uint32_t newval
|
||||
) {
|
||||
const long key = y16t_table_at(x, y);
|
||||
const uint32_t odval = htonl(newval);
|
||||
|
||||
if(key && fseek(fh, key, SEEK_CUR) == -1)
|
||||
return -EIO;
|
||||
if(fwrite(&newval, 4, 1, fh) != 1)
|
||||
if(fwrite(&odval, 4, 1, fh) != 1)
|
||||
return -EIO;
|
||||
if(key && fseek(fh, -key, SEEK_CUR) == -1)
|
||||
return -EIO;
|
||||
|
@ -63,8 +65,8 @@ int y16t_idx_foreach_x(
|
|||
offset = key;
|
||||
if(fread(&value, 4, 1, fh) != 1)
|
||||
return -EIO;
|
||||
int tmp = callback(value, context);
|
||||
if(tmp != 0) return tmp;
|
||||
int tmp = callback(ntohl(value), context);
|
||||
if(tmp) return tmp;
|
||||
}
|
||||
|
||||
if(offset && fseek(fh, -offset, SEEK_CUR) == -1)
|
||||
|
@ -90,8 +92,8 @@ int y16t_idx_foreach_y(
|
|||
offset = key;
|
||||
if(fread(&value, 4, 1, fh) != 1)
|
||||
return -EIO;
|
||||
int tmp = callback(value, context);
|
||||
if(tmp != 0) return tmp;
|
||||
int tmp = callback(ntohl(value), context);
|
||||
if(tmp) return tmp;
|
||||
}
|
||||
|
||||
if(offset && fseek(fh, -offset, SEEK_CUR) == -1)
|
|
@ -7,7 +7,7 @@ project('y16t 16bit-field quad tree library', 'c',
|
|||
install_headers('y16t.h')
|
||||
|
||||
liby16t = shared_library('y16t',
|
||||
files('hilbert.c', 'y16t.c'),
|
||||
files('hilbert.c', 'idx.c'),
|
||||
version : '0.0.0',
|
||||
c_args : ['-fno-plt', '-fno-unwind-tables', '-fno-exceptions', '-Werror=return-type'],
|
||||
include_directories : include_directories('.'),
|
||||
|
|
Loading…
Reference in a new issue