select data structure added
This commit is contained in:
parent
8203d56952
commit
7e265956c9
36
src/Makefile
36
src/Makefile
@ -60,7 +60,7 @@ libcmph_la_LIBADD =
|
|||||||
am_libcmph_la_OBJECTS = hash.lo jenkins_hash.lo vstack.lo vqueue.lo \
|
am_libcmph_la_OBJECTS = hash.lo jenkins_hash.lo vstack.lo vqueue.lo \
|
||||||
graph.lo cmph.lo cmph_structs.lo chm.lo bmz.lo bmz8.lo bdz.lo \
|
graph.lo cmph.lo cmph_structs.lo chm.lo bmz.lo bmz8.lo bdz.lo \
|
||||||
bdz_ph.lo buffer_manager.lo buffer_entry.lo brz.lo fch.lo \
|
bdz_ph.lo buffer_manager.lo buffer_entry.lo brz.lo fch.lo \
|
||||||
fch_buckets.lo
|
fch_buckets.lo select.lo
|
||||||
libcmph_la_OBJECTS = $(am_libcmph_la_OBJECTS)
|
libcmph_la_OBJECTS = $(am_libcmph_la_OBJECTS)
|
||||||
libcmph_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
libcmph_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
@ -98,7 +98,7 @@ AUTOMAKE = ${SHELL} /home/fbotelho/papers/conferences/djamel/cmph/missing --run
|
|||||||
AWK = gawk
|
AWK = gawk
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CCDEPMODE = depmode=gcc3
|
CCDEPMODE = depmode=gcc3
|
||||||
CFLAGS = -O3
|
CFLAGS = -O3 -Wall -Werror -lm
|
||||||
CPP = gcc -E
|
CPP = gcc -E
|
||||||
CPPFLAGS =
|
CPPFLAGS =
|
||||||
CYGPATH_W = echo
|
CYGPATH_W = echo
|
||||||
@ -120,8 +120,8 @@ INSTALL_PROGRAM = ${INSTALL}
|
|||||||
INSTALL_SCRIPT = ${INSTALL}
|
INSTALL_SCRIPT = ${INSTALL}
|
||||||
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
|
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
|
||||||
LD = /usr/bin/ld -m elf_x86_64
|
LD = /usr/bin/ld -m elf_x86_64
|
||||||
LDFLAGS = -lm
|
LDFLAGS =
|
||||||
LIBM = -lm
|
LIBM =
|
||||||
LIBOBJS =
|
LIBOBJS =
|
||||||
LIBS =
|
LIBS =
|
||||||
LIBTOOL = $(SHELL) $(top_builddir)/libtool
|
LIBTOOL = $(SHELL) $(top_builddir)/libtool
|
||||||
@ -201,26 +201,13 @@ top_builddir = ..
|
|||||||
top_srcdir = ..
|
top_srcdir = ..
|
||||||
lib_LTLIBRARIES = libcmph.la
|
lib_LTLIBRARIES = libcmph.la
|
||||||
include_HEADERS = cmph.h cmph_types.h
|
include_HEADERS = cmph.h cmph_types.h
|
||||||
libcmph_la_SOURCES = debug.h\
|
libcmph_la_SOURCES = hash.c jenkins_hash.c\
|
||||||
bitbool.h\
|
vstack.c vqueue.c\
|
||||||
cmph_types.h\
|
graph.c cmph.c cmph_structs.c\
|
||||||
hash.h hash_state.h hash.c\
|
chm.c bmz.c bmz8.c bdz.c bdz_ph.c\
|
||||||
jenkins_hash.h jenkins_hash.c\
|
buffer_manager.c buffer_entry.c\
|
||||||
vstack.h vstack.c\
|
brz.c fch.c fch_buckets.c \
|
||||||
vqueue.h vqueue.c\
|
select.c
|
||||||
graph.h graph.c\
|
|
||||||
cmph.h cmph.c\
|
|
||||||
cmph_structs.h cmph_structs.c\
|
|
||||||
chm.h chm_structs.h chm.c\
|
|
||||||
bmz.h bmz_structs.h bmz.c\
|
|
||||||
bmz8.h bmz8_structs.h bmz8.c\
|
|
||||||
bdz.h bdz_structs.h bdz.c\
|
|
||||||
bdz_ph.h bdz_structs_ph.h bdz_ph.c\
|
|
||||||
buffer_manager.h buffer_manager.c\
|
|
||||||
buffer_entry.h buffer_entry.c\
|
|
||||||
brz.h brz_structs.h brz.c\
|
|
||||||
fch.h fch_structs.h fch.c\
|
|
||||||
fch_buckets.h fch_buckets.c
|
|
||||||
|
|
||||||
libcmph_la_LDFLAGS = -version-info 0:0:0
|
libcmph_la_LDFLAGS = -version-info 0:0:0
|
||||||
cmph_SOURCES = main.c wingetopt.h wingetopt.c
|
cmph_SOURCES = main.c wingetopt.h wingetopt.c
|
||||||
@ -341,6 +328,7 @@ include ./$(DEPDIR)/graph.Plo
|
|||||||
include ./$(DEPDIR)/hash.Plo
|
include ./$(DEPDIR)/hash.Plo
|
||||||
include ./$(DEPDIR)/jenkins_hash.Plo
|
include ./$(DEPDIR)/jenkins_hash.Plo
|
||||||
include ./$(DEPDIR)/main.Po
|
include ./$(DEPDIR)/main.Po
|
||||||
|
include ./$(DEPDIR)/select.Plo
|
||||||
include ./$(DEPDIR)/vqueue.Plo
|
include ./$(DEPDIR)/vqueue.Plo
|
||||||
include ./$(DEPDIR)/vstack.Plo
|
include ./$(DEPDIR)/vstack.Plo
|
||||||
include ./$(DEPDIR)/wingetopt.Po
|
include ./$(DEPDIR)/wingetopt.Po
|
||||||
|
@ -1,26 +1,13 @@
|
|||||||
bin_PROGRAMS = cmph
|
bin_PROGRAMS = cmph
|
||||||
lib_LTLIBRARIES = libcmph.la
|
lib_LTLIBRARIES = libcmph.la
|
||||||
include_HEADERS = cmph.h cmph_types.h
|
include_HEADERS = cmph.h cmph_types.h
|
||||||
libcmph_la_SOURCES = debug.h\
|
libcmph_la_SOURCES = hash.c jenkins_hash.c\
|
||||||
bitbool.h\
|
vstack.c vqueue.c\
|
||||||
cmph_types.h\
|
graph.c cmph.c cmph_structs.c\
|
||||||
hash.h hash_state.h hash.c\
|
chm.c bmz.c bmz8.c bdz.c bdz_ph.c\
|
||||||
jenkins_hash.h jenkins_hash.c\
|
buffer_manager.c buffer_entry.c\
|
||||||
vstack.h vstack.c\
|
brz.c fch.c fch_buckets.c \
|
||||||
vqueue.h vqueue.c\
|
select.c
|
||||||
graph.h graph.c\
|
|
||||||
cmph.h cmph.c\
|
|
||||||
cmph_structs.h cmph_structs.c\
|
|
||||||
chm.h chm_structs.h chm.c\
|
|
||||||
bmz.h bmz_structs.h bmz.c\
|
|
||||||
bmz8.h bmz8_structs.h bmz8.c\
|
|
||||||
bdz.h bdz_structs.h bdz.c\
|
|
||||||
bdz_ph.h bdz_structs_ph.h bdz_ph.c\
|
|
||||||
buffer_manager.h buffer_manager.c\
|
|
||||||
buffer_entry.h buffer_entry.c\
|
|
||||||
brz.h brz_structs.h brz.c\
|
|
||||||
fch.h fch_structs.h fch.c\
|
|
||||||
fch_buckets.h fch_buckets.c
|
|
||||||
|
|
||||||
libcmph_la_LDFLAGS = -version-info 0:0:0
|
libcmph_la_LDFLAGS = -version-info 0:0:0
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ libcmph_la_LIBADD =
|
|||||||
am_libcmph_la_OBJECTS = hash.lo jenkins_hash.lo vstack.lo vqueue.lo \
|
am_libcmph_la_OBJECTS = hash.lo jenkins_hash.lo vstack.lo vqueue.lo \
|
||||||
graph.lo cmph.lo cmph_structs.lo chm.lo bmz.lo bmz8.lo bdz.lo \
|
graph.lo cmph.lo cmph_structs.lo chm.lo bmz.lo bmz8.lo bdz.lo \
|
||||||
bdz_ph.lo buffer_manager.lo buffer_entry.lo brz.lo fch.lo \
|
bdz_ph.lo buffer_manager.lo buffer_entry.lo brz.lo fch.lo \
|
||||||
fch_buckets.lo
|
fch_buckets.lo select.lo
|
||||||
libcmph_la_OBJECTS = $(am_libcmph_la_OBJECTS)
|
libcmph_la_OBJECTS = $(am_libcmph_la_OBJECTS)
|
||||||
libcmph_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
libcmph_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
@ -201,26 +201,13 @@ top_builddir = @top_builddir@
|
|||||||
top_srcdir = @top_srcdir@
|
top_srcdir = @top_srcdir@
|
||||||
lib_LTLIBRARIES = libcmph.la
|
lib_LTLIBRARIES = libcmph.la
|
||||||
include_HEADERS = cmph.h cmph_types.h
|
include_HEADERS = cmph.h cmph_types.h
|
||||||
libcmph_la_SOURCES = debug.h\
|
libcmph_la_SOURCES = hash.c jenkins_hash.c\
|
||||||
bitbool.h\
|
vstack.c vqueue.c\
|
||||||
cmph_types.h\
|
graph.c cmph.c cmph_structs.c\
|
||||||
hash.h hash_state.h hash.c\
|
chm.c bmz.c bmz8.c bdz.c bdz_ph.c\
|
||||||
jenkins_hash.h jenkins_hash.c\
|
buffer_manager.c buffer_entry.c\
|
||||||
vstack.h vstack.c\
|
brz.c fch.c fch_buckets.c \
|
||||||
vqueue.h vqueue.c\
|
select.c
|
||||||
graph.h graph.c\
|
|
||||||
cmph.h cmph.c\
|
|
||||||
cmph_structs.h cmph_structs.c\
|
|
||||||
chm.h chm_structs.h chm.c\
|
|
||||||
bmz.h bmz_structs.h bmz.c\
|
|
||||||
bmz8.h bmz8_structs.h bmz8.c\
|
|
||||||
bdz.h bdz_structs.h bdz.c\
|
|
||||||
bdz_ph.h bdz_structs_ph.h bdz_ph.c\
|
|
||||||
buffer_manager.h buffer_manager.c\
|
|
||||||
buffer_entry.h buffer_entry.c\
|
|
||||||
brz.h brz_structs.h brz.c\
|
|
||||||
fch.h fch_structs.h fch.c\
|
|
||||||
fch_buckets.h fch_buckets.c
|
|
||||||
|
|
||||||
libcmph_la_LDFLAGS = -version-info 0:0:0
|
libcmph_la_LDFLAGS = -version-info 0:0:0
|
||||||
cmph_SOURCES = main.c wingetopt.h wingetopt.c
|
cmph_SOURCES = main.c wingetopt.h wingetopt.c
|
||||||
@ -341,6 +328,7 @@ distclean-compile:
|
|||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jenkins_hash.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jenkins_hash.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/select.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vqueue.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vqueue.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vstack.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vstack.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wingetopt.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wingetopt.Po@am__quote@
|
||||||
|
42
src/bdz.c
42
src/bdz.c
@ -468,27 +468,28 @@ int bdz_dump(cmph_t *mphf, FILE *fd)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
bdz_data_t *data = (bdz_data_t *)mphf->data;
|
bdz_data_t *data = (bdz_data_t *)mphf->data;
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
hash_state_dump(data->hl, &buf, &buflen);
|
hash_state_dump(data->hl, &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->r), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->r), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
|
|
||||||
cmph_uint32 sizeg = ceil(data->n/4.0);
|
cmph_uint32 sizeg = ceil(data->n/4.0);
|
||||||
fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd);
|
||||||
|
|
||||||
fwrite(&(data->k), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->k), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->b), sizeof(cmph_uint8), (size_t)1, fd);
|
nbytes = fwrite(&(data->b), sizeof(cmph_uint8), (size_t)1, fd);
|
||||||
fwrite(&(data->ranktablesize), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->ranktablesize), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
|
|
||||||
fwrite(data->ranktable, sizeof(cmph_uint32)*(data->ranktablesize), (size_t)1, fd);
|
nbytes = fwrite(data->ranktable, sizeof(cmph_uint32)*(data->ranktablesize), (size_t)1, fd);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
@ -502,33 +503,34 @@ void bdz_load(FILE *f, cmph_t *mphf)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen, sizeg;
|
cmph_uint32 buflen, sizeg;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
bdz_data_t *bdz = (bdz_data_t *)malloc(sizeof(bdz_data_t));
|
bdz_data_t *bdz = (bdz_data_t *)malloc(sizeof(bdz_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading bdz mphf\n");
|
DEBUGP("Loading bdz mphf\n");
|
||||||
mphf->data = bdz;
|
mphf->data = bdz;
|
||||||
|
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
bdz->hl = hash_state_load(buf, buflen);
|
bdz->hl = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(bdz->n), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz->n), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bdz->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bdz->r), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz->r), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
sizeg = ceil(bdz->n/4.0);
|
sizeg = ceil(bdz->n/4.0);
|
||||||
bdz->g = (cmph_uint8 *)calloc((size_t)(sizeg), sizeof(cmph_uint8));
|
bdz->g = (cmph_uint8 *)calloc((size_t)(sizeg), sizeof(cmph_uint8));
|
||||||
fread(bdz->g, sizeg*sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(bdz->g, sizeg*sizeof(cmph_uint8), (size_t)1, f);
|
||||||
|
|
||||||
fread(&(bdz->k), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz->k), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bdz->b), sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(&(bdz->b), sizeof(cmph_uint8), (size_t)1, f);
|
||||||
fread(&(bdz->ranktablesize), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz->ranktablesize), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
|
|
||||||
bdz->ranktable = (cmph_uint32 *)calloc((size_t)bdz->ranktablesize, sizeof(cmph_uint32));
|
bdz->ranktable = (cmph_uint32 *)calloc((size_t)bdz->ranktablesize, sizeof(cmph_uint32));
|
||||||
fread(bdz->ranktable, sizeof(cmph_uint32)*(bdz->ranktablesize), (size_t)1, f);
|
nbytes = fread(bdz->ranktable, sizeof(cmph_uint32)*(bdz->ranktablesize), (size_t)1, f);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i = 0;
|
cmph_uint32 i = 0;
|
||||||
|
26
src/bdz_ph.c
26
src/bdz_ph.c
@ -432,20 +432,21 @@ int bdz_ph_dump(cmph_t *mphf, FILE *fd)
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 sizeg = 0;
|
cmph_uint32 sizeg = 0;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
bdz_ph_data_t *data = (bdz_ph_data_t *)mphf->data;
|
bdz_ph_data_t *data = (bdz_ph_data_t *)mphf->data;
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
hash_state_dump(data->hl, &buf, &buflen);
|
hash_state_dump(data->hl, &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->r), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->r), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
sizeg = ceil(data->n/5.0);
|
sizeg = ceil(data->n/5.0);
|
||||||
fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
@ -461,26 +462,27 @@ void bdz_ph_load(FILE *f, cmph_t *mphf)
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 sizeg = 0;
|
cmph_uint32 sizeg = 0;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
bdz_ph_data_t *bdz_ph = (bdz_ph_data_t *)malloc(sizeof(bdz_ph_data_t));
|
bdz_ph_data_t *bdz_ph = (bdz_ph_data_t *)malloc(sizeof(bdz_ph_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading bdz_ph mphf\n");
|
DEBUGP("Loading bdz_ph mphf\n");
|
||||||
mphf->data = bdz_ph;
|
mphf->data = bdz_ph;
|
||||||
|
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
bdz_ph->hl = hash_state_load(buf, buflen);
|
bdz_ph->hl = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(bdz_ph->n), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz_ph->n), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bdz_ph->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz_ph->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bdz_ph->r), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bdz_ph->r), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
sizeg = ceil(bdz_ph->n/5.0);
|
sizeg = ceil(bdz_ph->n/5.0);
|
||||||
bdz_ph->g = (cmph_uint8 *)calloc((size_t)sizeg, sizeof(cmph_uint8));
|
bdz_ph->g = (cmph_uint8 *)calloc((size_t)sizeg, sizeof(cmph_uint8));
|
||||||
fread(bdz_ph->g, sizeg*sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(bdz_ph->g, sizeg*sizeof(cmph_uint8), (size_t)1, f);
|
||||||
|
|
||||||
/* #ifdef DEBUG
|
/* #ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
|
31
src/bmz.c
31
src/bmz.c
@ -448,26 +448,27 @@ int bmz_dump(cmph_t *mphf, FILE *fd)
|
|||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 two = 2; //number of hash functions
|
cmph_uint32 two = 2; //number of hash functions
|
||||||
bmz_data_t *data = (bmz_data_t *)mphf->data;
|
bmz_data_t *data = (bmz_data_t *)mphf->data;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[0], &buf, &buflen);
|
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
|
|
||||||
fwrite(data->g, sizeof(cmph_uint32)*(data->n), (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint32)*(data->n), (size_t)1, fd);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
@ -484,31 +485,31 @@ void bmz_load(FILE *f, cmph_t *mphf)
|
|||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
bmz_data_t *bmz = (bmz_data_t *)malloc(sizeof(bmz_data_t));
|
bmz_data_t *bmz = (bmz_data_t *)malloc(sizeof(bmz_data_t));
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
DEBUGP("Loading bmz mphf\n");
|
DEBUGP("Loading bmz mphf\n");
|
||||||
mphf->data = bmz;
|
mphf->data = bmz;
|
||||||
fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||||
bmz->hashes[nhashes] = NULL;
|
bmz->hashes[nhashes] = NULL;
|
||||||
DEBUGP("Reading %u hashes\n", nhashes);
|
DEBUGP("Reading %u hashes\n", nhashes);
|
||||||
for (i = 0; i < nhashes; ++i)
|
for (i = 0; i < nhashes; ++i)
|
||||||
{
|
{
|
||||||
hash_state_t *state = NULL;
|
hash_state_t *state = NULL;
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
state = hash_state_load(buf, buflen);
|
state = hash_state_load(buf, buflen);
|
||||||
bmz->hashes[i] = state;
|
bmz->hashes[i] = state;
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(bmz->n), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bmz->n), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(bmz->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(bmz->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
|
|
||||||
bmz->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*bmz->n);
|
bmz->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*bmz->n);
|
||||||
fread(bmz->g, bmz->n*sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(bmz->g, bmz->n*sizeof(cmph_uint32), (size_t)1, f);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
|
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
|
||||||
|
30
src/bmz8.c
30
src/bmz8.c
@ -458,26 +458,27 @@ int bmz8_dump(cmph_t *mphf, FILE *fd)
|
|||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint8 two = 2; //number of hash functions
|
cmph_uint8 two = 2; //number of hash functions
|
||||||
bmz8_data_t *data = (bmz8_data_t *)mphf->data;
|
bmz8_data_t *data = (bmz8_data_t *)mphf->data;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
fwrite(&two, sizeof(cmph_uint8), (size_t)1, fd);
|
nbytes = fwrite(&two, sizeof(cmph_uint8), (size_t)1, fd);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[0], &buf, &buflen);
|
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->n), sizeof(cmph_uint8), (size_t)1, fd);
|
nbytes = fwrite(&(data->n), sizeof(cmph_uint8), (size_t)1, fd);
|
||||||
fwrite(&(data->m), sizeof(cmph_uint8), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint8), (size_t)1, fd);
|
||||||
|
|
||||||
fwrite(data->g, sizeof(cmph_uint8)*(data->n), (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint8)*(data->n), (size_t)1, fd);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
||||||
@ -492,32 +493,33 @@ void bmz8_load(FILE *f, cmph_t *mphf)
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint8 i;
|
cmph_uint8 i;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
bmz8_data_t *bmz8 = (bmz8_data_t *)malloc(sizeof(bmz8_data_t));
|
bmz8_data_t *bmz8 = (bmz8_data_t *)malloc(sizeof(bmz8_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading bmz8 mphf\n");
|
DEBUGP("Loading bmz8 mphf\n");
|
||||||
mphf->data = bmz8;
|
mphf->data = bmz8;
|
||||||
fread(&nhashes, sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(&nhashes, sizeof(cmph_uint8), (size_t)1, f);
|
||||||
bmz8->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
bmz8->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||||
bmz8->hashes[nhashes] = NULL;
|
bmz8->hashes[nhashes] = NULL;
|
||||||
DEBUGP("Reading %u hashes\n", nhashes);
|
DEBUGP("Reading %u hashes\n", nhashes);
|
||||||
for (i = 0; i < nhashes; ++i)
|
for (i = 0; i < nhashes; ++i)
|
||||||
{
|
{
|
||||||
hash_state_t *state = NULL;
|
hash_state_t *state = NULL;
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
state = hash_state_load(buf, buflen);
|
state = hash_state_load(buf, buflen);
|
||||||
bmz8->hashes[i] = state;
|
bmz8->hashes[i] = state;
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(bmz8->n), sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(&(bmz8->n), sizeof(cmph_uint8), (size_t)1, f);
|
||||||
fread(&(bmz8->m), sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(&(bmz8->m), sizeof(cmph_uint8), (size_t)1, f);
|
||||||
|
|
||||||
bmz8->g = (cmph_uint8 *)malloc(sizeof(cmph_uint8)*bmz8->n);
|
bmz8->g = (cmph_uint8 *)malloc(sizeof(cmph_uint8)*bmz8->n);
|
||||||
fread(bmz8->g, bmz8->n*sizeof(cmph_uint8), (size_t)1, f);
|
nbytes = fread(bmz8->g, bmz8->n*sizeof(cmph_uint8), (size_t)1, f);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < bmz8->n; ++i) fprintf(stderr, "%u ", bmz8->g[i]);
|
for (i = 0; i < bmz8->n; ++i) fprintf(stderr, "%u ", bmz8->g[i]);
|
||||||
|
55
src/brz.c
55
src/brz.c
@ -227,6 +227,7 @@ static int brz_gen_mphf(cmph_config_t *mph)
|
|||||||
cmph_uint32 *buffer_h0 = NULL;
|
cmph_uint32 *buffer_h0 = NULL;
|
||||||
cmph_uint32 nflushes = 0;
|
cmph_uint32 nflushes = 0;
|
||||||
cmph_uint32 h0;
|
cmph_uint32 h0;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
FILE * tmp_fd = NULL;
|
FILE * tmp_fd = NULL;
|
||||||
buffer_manager_t * buff_manager = NULL;
|
buffer_manager_t * buff_manager = NULL;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
@ -280,7 +281,7 @@ static int brz_gen_mphf(cmph_config_t *mph)
|
|||||||
for(i = 0; i < nkeys_in_buffer; i++)
|
for(i = 0; i < nkeys_in_buffer; i++)
|
||||||
{
|
{
|
||||||
memcpy(&keylen1, buffer + keys_index[i], sizeof(keylen1));
|
memcpy(&keylen1, buffer + keys_index[i], sizeof(keylen1));
|
||||||
fwrite(buffer + keys_index[i], (size_t)1, keylen1 + sizeof(keylen1), tmp_fd);
|
nbytes = fwrite(buffer + keys_index[i], (size_t)1, keylen1 + sizeof(keylen1), tmp_fd);
|
||||||
}
|
}
|
||||||
nkeys_in_buffer = 0;
|
nkeys_in_buffer = 0;
|
||||||
memory_usage = 0;
|
memory_usage = 0;
|
||||||
@ -340,7 +341,7 @@ static int brz_gen_mphf(cmph_config_t *mph)
|
|||||||
for(i = 0; i < nkeys_in_buffer; i++)
|
for(i = 0; i < nkeys_in_buffer; i++)
|
||||||
{
|
{
|
||||||
memcpy(&keylen1, buffer + keys_index[i], sizeof(keylen1));
|
memcpy(&keylen1, buffer + keys_index[i], sizeof(keylen1));
|
||||||
fwrite(buffer + keys_index[i], (size_t)1, keylen1 + sizeof(keylen1), tmp_fd);
|
nbytes = fwrite(buffer + keys_index[i], (size_t)1, keylen1 + sizeof(keylen1), tmp_fd);
|
||||||
}
|
}
|
||||||
nkeys_in_buffer = 0;
|
nkeys_in_buffer = 0;
|
||||||
memory_usage = 0;
|
memory_usage = 0;
|
||||||
@ -359,12 +360,12 @@ static int brz_gen_mphf(cmph_config_t *mph)
|
|||||||
fprintf(stderr, "\nMPHF generation \n");
|
fprintf(stderr, "\nMPHF generation \n");
|
||||||
}
|
}
|
||||||
/* Starting to dump to disk the resultant MPHF: __cmph_dump function */
|
/* Starting to dump to disk the resultant MPHF: __cmph_dump function */
|
||||||
fwrite(cmph_names[CMPH_BRZ], (size_t)(strlen(cmph_names[CMPH_BRZ]) + 1), (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(cmph_names[CMPH_BRZ], (size_t)(strlen(cmph_names[CMPH_BRZ]) + 1), (size_t)1, brz->mphf_fd);
|
||||||
fwrite(&(brz->m), sizeof(brz->m), (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(&(brz->m), sizeof(brz->m), (size_t)1, brz->mphf_fd);
|
||||||
fwrite(&(brz->c), sizeof(double), (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(&(brz->c), sizeof(double), (size_t)1, brz->mphf_fd);
|
||||||
fwrite(&(brz->algo), sizeof(brz->algo), (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(&(brz->algo), sizeof(brz->algo), (size_t)1, brz->mphf_fd);
|
||||||
fwrite(&(brz->k), sizeof(cmph_uint32), (size_t)1, brz->mphf_fd); // number of MPHFs
|
nbytes = fwrite(&(brz->k), sizeof(cmph_uint32), (size_t)1, brz->mphf_fd); // number of MPHFs
|
||||||
fwrite(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, brz->mphf_fd);
|
||||||
|
|
||||||
//tmp_fds = (FILE **)calloc(nflushes, sizeof(FILE *));
|
//tmp_fds = (FILE **)calloc(nflushes, sizeof(FILE *));
|
||||||
buff_manager = buffer_manager_new(brz->memory_availability, nflushes);
|
buff_manager = buffer_manager_new(brz->memory_availability, nflushes);
|
||||||
@ -473,7 +474,7 @@ static int brz_gen_mphf(cmph_config_t *mph)
|
|||||||
break;
|
break;
|
||||||
default: assert(0);
|
default: assert(0);
|
||||||
}
|
}
|
||||||
fwrite(bufmphf, (size_t)buflenmphf, (size_t)1, brz->mphf_fd);
|
nbytes = fwrite(bufmphf, (size_t)buflenmphf, (size_t)1, brz->mphf_fd);
|
||||||
free(bufmphf);
|
free(bufmphf);
|
||||||
bufmphf = NULL;
|
bufmphf = NULL;
|
||||||
cmph_config_destroy(config);
|
cmph_config_destroy(config);
|
||||||
@ -557,17 +558,18 @@ int brz_dump(cmph_t *mphf, FILE *fd)
|
|||||||
brz_data_t *data = (brz_data_t *)mphf->data;
|
brz_data_t *data = (brz_data_t *)mphf->data;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
DEBUGP("Dumping brzf\n");
|
DEBUGP("Dumping brzf\n");
|
||||||
// The initial part of the MPHF have already been dumped to disk during construction
|
// The initial part of the MPHF have already been dumped to disk during construction
|
||||||
// Dumping h0
|
// Dumping h0
|
||||||
hash_state_dump(data->h0, &buf, &buflen);
|
hash_state_dump(data->h0, &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
// Dumping m and the vector offset.
|
// Dumping m and the vector offset.
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(data->offset, sizeof(cmph_uint32)*(data->k), (size_t)1, fd);
|
nbytes = fwrite(data->offset, sizeof(cmph_uint32)*(data->k), (size_t)1, fd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,16 +577,17 @@ void brz_load(FILE *f, cmph_t *mphf)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
cmph_uint32 i, n;
|
cmph_uint32 i, n;
|
||||||
brz_data_t *brz = (brz_data_t *)malloc(sizeof(brz_data_t));
|
brz_data_t *brz = (brz_data_t *)malloc(sizeof(brz_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading brz mphf\n");
|
DEBUGP("Loading brz mphf\n");
|
||||||
mphf->data = brz;
|
mphf->data = brz;
|
||||||
fread(&(brz->c), sizeof(double), (size_t)1, f);
|
nbytes = fread(&(brz->c), sizeof(double), (size_t)1, f);
|
||||||
fread(&(brz->algo), sizeof(brz->algo), (size_t)1, f); // Reading algo.
|
nbytes = fread(&(brz->algo), sizeof(brz->algo), (size_t)1, f); // Reading algo.
|
||||||
fread(&(brz->k), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(brz->k), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
brz->size = (cmph_uint8 *) malloc(sizeof(cmph_uint8)*brz->k);
|
brz->size = (cmph_uint8 *) malloc(sizeof(cmph_uint8)*brz->k);
|
||||||
fread(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, f);
|
nbytes = fread(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, f);
|
||||||
brz->h1 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
brz->h1 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
||||||
brz->h2 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
brz->h2 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
||||||
brz->g = (cmph_uint8 **) calloc((size_t)brz->k, sizeof(cmph_uint8 *));
|
brz->g = (cmph_uint8 **) calloc((size_t)brz->k, sizeof(cmph_uint8 *));
|
||||||
@ -593,17 +596,17 @@ void brz_load(FILE *f, cmph_t *mphf)
|
|||||||
for(i = 0; i < brz->k; i++)
|
for(i = 0; i < brz->k; i++)
|
||||||
{
|
{
|
||||||
// h1
|
// h1
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state 1 has %u bytes\n", buflen);
|
DEBUGP("Hash state 1 has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
brz->h1[i] = hash_state_load(buf, buflen);
|
brz->h1[i] = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
//h2
|
//h2
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state 2 has %u bytes\n", buflen);
|
DEBUGP("Hash state 2 has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
brz->h2[i] = hash_state_load(buf, buflen);
|
brz->h2[i] = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
switch(brz->algo)
|
switch(brz->algo)
|
||||||
@ -618,20 +621,20 @@ void brz_load(FILE *f, cmph_t *mphf)
|
|||||||
}
|
}
|
||||||
DEBUGP("g_i has %u bytes\n", n);
|
DEBUGP("g_i has %u bytes\n", n);
|
||||||
brz->g[i] = (cmph_uint8 *)calloc((size_t)n, sizeof(cmph_uint8));
|
brz->g[i] = (cmph_uint8 *)calloc((size_t)n, sizeof(cmph_uint8));
|
||||||
fread(brz->g[i], sizeof(cmph_uint8)*n, (size_t)1, f);
|
nbytes = fread(brz->g[i], sizeof(cmph_uint8)*n, (size_t)1, f);
|
||||||
}
|
}
|
||||||
//loading h0
|
//loading h0
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
brz->h0 = hash_state_load(buf, buflen);
|
brz->h0 = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
//loading c, m, and the vector offset.
|
//loading c, m, and the vector offset.
|
||||||
fread(&(brz->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(brz->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
brz->offset = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*brz->k);
|
brz->offset = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*brz->k);
|
||||||
fread(brz->offset, sizeof(cmph_uint32)*(brz->k), (size_t)1, f);
|
nbytes = fread(brz->offset, sizeof(cmph_uint32)*(brz->k), (size_t)1, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
src/chm.c
32
src/chm.c
@ -204,25 +204,27 @@ int chm_dump(cmph_t *mphf, FILE *fd)
|
|||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 two = 2; //number of hash functions
|
cmph_uint32 two = 2; //number of hash functions
|
||||||
chm_data_t *data = (chm_data_t *)mphf->data;
|
chm_data_t *data = (chm_data_t *)mphf->data;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
|
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
hash_state_dump(data->hashes[0], &buf, &buflen);
|
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
|
|
||||||
fwrite(data->g, sizeof(cmph_uint32)*data->n, (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint32)*data->n, (size_t)1, fd);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
||||||
@ -238,31 +240,31 @@ void chm_load(FILE *f, cmph_t *mphf)
|
|||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
chm_data_t *chm = (chm_data_t *)malloc(sizeof(chm_data_t));
|
chm_data_t *chm = (chm_data_t *)malloc(sizeof(chm_data_t));
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
DEBUGP("Loading chm mphf\n");
|
DEBUGP("Loading chm mphf\n");
|
||||||
mphf->data = chm;
|
mphf->data = chm;
|
||||||
fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
chm->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
chm->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||||
chm->hashes[nhashes] = NULL;
|
chm->hashes[nhashes] = NULL;
|
||||||
DEBUGP("Reading %u hashes\n", nhashes);
|
DEBUGP("Reading %u hashes\n", nhashes);
|
||||||
for (i = 0; i < nhashes; ++i)
|
for (i = 0; i < nhashes; ++i)
|
||||||
{
|
{
|
||||||
hash_state_t *state = NULL;
|
hash_state_t *state = NULL;
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
state = hash_state_load(buf, buflen);
|
state = hash_state_load(buf, buflen);
|
||||||
chm->hashes[i] = state;
|
chm->hashes[i] = state;
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(chm->n), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(chm->n), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(chm->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(chm->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
|
|
||||||
chm->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*chm->n);
|
chm->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*chm->n);
|
||||||
fread(chm->g, chm->n*sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(chm->g, chm->n*sizeof(cmph_uint32), (size_t)1, f);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < chm->n; ++i) fprintf(stderr, "%u ", chm->g[i]);
|
for (i = 0; i < chm->n; ++i) fprintf(stderr, "%u ", chm->g[i]);
|
||||||
|
@ -150,11 +150,12 @@ static void key_vector_rewind(void *data)
|
|||||||
static cmph_uint32 count_nlfile_keys(FILE *fd)
|
static cmph_uint32 count_nlfile_keys(FILE *fd)
|
||||||
{
|
{
|
||||||
cmph_uint32 count = 0;
|
cmph_uint32 count = 0;
|
||||||
|
register char * ptr;
|
||||||
rewind(fd);
|
rewind(fd);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
fgets(buf, BUFSIZ, fd);
|
ptr = fgets(buf, BUFSIZ, fd);
|
||||||
if (feof(fd)) break;
|
if (feof(fd)) break;
|
||||||
if (buf[strlen(buf) - 1] != '\n') continue;
|
if (buf[strlen(buf) - 1] != '\n') continue;
|
||||||
++count;
|
++count;
|
||||||
|
@ -24,8 +24,9 @@ void __config_destroy(cmph_config_t *mph)
|
|||||||
|
|
||||||
void __cmph_dump(cmph_t *mphf, FILE *fd)
|
void __cmph_dump(cmph_t *mphf, FILE *fd)
|
||||||
{
|
{
|
||||||
fwrite(cmph_names[mphf->algo], (size_t)(strlen(cmph_names[mphf->algo]) + 1), (size_t)1, fd);
|
register cmph_uint32 nbytes;
|
||||||
fwrite(&(mphf->size), sizeof(mphf->size), (size_t)1, fd);
|
nbytes = fwrite(cmph_names[mphf->algo], (size_t)(strlen(cmph_names[mphf->algo]) + 1), (size_t)1, fd);
|
||||||
|
nbytes = fwrite(&(mphf->size), sizeof(mphf->size), (size_t)1, fd);
|
||||||
}
|
}
|
||||||
cmph_t *__cmph_load(FILE *f)
|
cmph_t *__cmph_load(FILE *f)
|
||||||
{
|
{
|
||||||
@ -34,6 +35,7 @@ cmph_t *__cmph_load(FILE *f)
|
|||||||
char algo_name[BUFSIZ];
|
char algo_name[BUFSIZ];
|
||||||
char *ptr = algo_name;
|
char *ptr = algo_name;
|
||||||
CMPH_ALGO algo = CMPH_COUNT;
|
CMPH_ALGO algo = CMPH_COUNT;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
|
|
||||||
DEBUGP("Loading mphf\n");
|
DEBUGP("Loading mphf\n");
|
||||||
while(1)
|
while(1)
|
||||||
@ -57,7 +59,7 @@ cmph_t *__cmph_load(FILE *f)
|
|||||||
}
|
}
|
||||||
mphf = (cmph_t *)malloc(sizeof(cmph_t));
|
mphf = (cmph_t *)malloc(sizeof(cmph_t));
|
||||||
mphf->algo = algo;
|
mphf->algo = algo;
|
||||||
fread(&(mphf->size), sizeof(mphf->size), (size_t)1, f);
|
nbytes = fread(&(mphf->size), sizeof(mphf->size), (size_t)1, f);
|
||||||
mphf->data = NULL;
|
mphf->data = NULL;
|
||||||
DEBUGP("Algorithm is %s and mphf is sized %u\n", cmph_names[algo], mphf->size);
|
DEBUGP("Algorithm is %s and mphf is sized %u\n", cmph_names[algo], mphf->size);
|
||||||
|
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
#ifndef __CMPH_TYPES_H__
|
#ifndef __CMPH_TYPES_H__
|
||||||
#define __CMPH_TYPES_H__
|
#define __CMPH_TYPES_H__
|
||||||
|
|
||||||
|
typedef char cmph_int8;
|
||||||
typedef unsigned char cmph_uint8;
|
typedef unsigned char cmph_uint8;
|
||||||
|
|
||||||
|
typedef short cmph_int16;
|
||||||
typedef unsigned short cmph_uint16;
|
typedef unsigned short cmph_uint16;
|
||||||
|
|
||||||
|
typedef int cmph_int32;
|
||||||
typedef unsigned int cmph_uint32;
|
typedef unsigned int cmph_uint32;
|
||||||
|
|
||||||
#if defined(__ia64) || defined(__x86_64__)
|
#if defined(__ia64) || defined(__x86_64__)
|
||||||
|
43
src/fch.c
43
src/fch.c
@ -316,27 +316,29 @@ int fch_dump(cmph_t *mphf, FILE *fd)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
|
|
||||||
fch_data_t *data = (fch_data_t *)mphf->data;
|
fch_data_t *data = (fch_data_t *)mphf->data;
|
||||||
__cmph_dump(mphf, fd);
|
__cmph_dump(mphf, fd);
|
||||||
|
|
||||||
hash_state_dump(data->h1, &buf, &buflen);
|
hash_state_dump(data->h1, &buf, &buflen);
|
||||||
//DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
//DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->h2, &buf, &buflen);
|
hash_state_dump(data->h2, &buf, &buflen);
|
||||||
//DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
//DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
nbytes = fwrite(buf, (size_t)buflen, (size_t)1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->c), sizeof(double), (size_t)1, fd);
|
nbytes = fwrite(&(data->c), sizeof(double), (size_t)1, fd);
|
||||||
fwrite(&(data->b), sizeof(cmph_uint32), (size_t)1, fd);
|
nbytes = fwrite(&(data->b), sizeof(cmph_uint32), (size_t)1, fd);
|
||||||
fwrite(&(data->p1), sizeof(double), (size_t)1, fd);
|
nbytes = fwrite(&(data->p1), sizeof(double), (size_t)1, fd);
|
||||||
fwrite(&(data->p2), sizeof(double), (size_t)1, fd);
|
nbytes = fwrite(&(data->p2), sizeof(double), (size_t)1, fd);
|
||||||
fwrite(data->g, sizeof(cmph_uint32)*(data->b), (size_t)1, fd);
|
nbytes = fwrite(data->g, sizeof(cmph_uint32)*(data->b), (size_t)1, fd);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
@ -350,16 +352,17 @@ void fch_load(FILE *f, cmph_t *mphf)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
cmph_uint32 buflen;
|
cmph_uint32 buflen;
|
||||||
|
register cmph_uint32 nbytes;
|
||||||
fch_data_t *fch = (fch_data_t *)malloc(sizeof(fch_data_t));
|
fch_data_t *fch = (fch_data_t *)malloc(sizeof(fch_data_t));
|
||||||
|
|
||||||
//DEBUGP("Loading fch mphf\n");
|
//DEBUGP("Loading fch mphf\n");
|
||||||
mphf->data = fch;
|
mphf->data = fch;
|
||||||
//DEBUGP("Reading h1\n");
|
//DEBUGP("Reading h1\n");
|
||||||
fch->h1 = NULL;
|
fch->h1 = NULL;
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
//DEBUGP("Hash state of h1 has %u bytes\n", buflen);
|
//DEBUGP("Hash state of h1 has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
fch->h1 = hash_state_load(buf, buflen);
|
fch->h1 = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
@ -367,23 +370,23 @@ void fch_load(FILE *f, cmph_t *mphf)
|
|||||||
mphf->data = fch;
|
mphf->data = fch;
|
||||||
//DEBUGP("Reading h2\n");
|
//DEBUGP("Reading h2\n");
|
||||||
fch->h2 = NULL;
|
fch->h2 = NULL;
|
||||||
fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
|
||||||
//DEBUGP("Hash state of h2 has %u bytes\n", buflen);
|
//DEBUGP("Hash state of h2 has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc((size_t)buflen);
|
buf = (char *)malloc((size_t)buflen);
|
||||||
fread(buf, (size_t)buflen, (size_t)1, f);
|
nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
|
||||||
fch->h2 = hash_state_load(buf, buflen);
|
fch->h2 = hash_state_load(buf, buflen);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
|
||||||
//DEBUGP("Reading m and n\n");
|
//DEBUGP("Reading m and n\n");
|
||||||
fread(&(fch->m), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(fch->m), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(fch->c), sizeof(double), (size_t)1, f);
|
nbytes = fread(&(fch->c), sizeof(double), (size_t)1, f);
|
||||||
fread(&(fch->b), sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(&(fch->b), sizeof(cmph_uint32), (size_t)1, f);
|
||||||
fread(&(fch->p1), sizeof(double), (size_t)1, f);
|
nbytes = fread(&(fch->p1), sizeof(double), (size_t)1, f);
|
||||||
fread(&(fch->p2), sizeof(double), (size_t)1, f);
|
nbytes = fread(&(fch->p2), sizeof(double), (size_t)1, f);
|
||||||
|
|
||||||
fch->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*fch->b);
|
fch->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*fch->b);
|
||||||
fread(fch->g, fch->b*sizeof(cmph_uint32), (size_t)1, f);
|
nbytes = fread(fch->g, fch->b*sizeof(cmph_uint32), (size_t)1, f);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cmph_uint32 i;
|
cmph_uint32 i;
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
|
@ -199,7 +199,7 @@ static int find_degree1_edge(graph_t *g, cmph_uint32 v, char *deleted, cmph_uint
|
|||||||
static void cyclic_del_edge(graph_t *g, cmph_uint32 v, char *deleted)
|
static void cyclic_del_edge(graph_t *g, cmph_uint32 v, char *deleted)
|
||||||
{
|
{
|
||||||
|
|
||||||
cmph_uint32 e;
|
cmph_uint32 e = 0;
|
||||||
char degree1;
|
char degree1;
|
||||||
cmph_uint32 v1 = v;
|
cmph_uint32 v1 = v;
|
||||||
cmph_uint32 v2 = 0;
|
cmph_uint32 v2 = 0;
|
||||||
|
@ -39,7 +39,7 @@ void jenkins_state_destroy(jenkins_state_t *state);
|
|||||||
*/
|
*/
|
||||||
void jenkins_state_pack(jenkins_state_t *state, void *jenkins_packed);
|
void jenkins_state_pack(jenkins_state_t *state, void *jenkins_packed);
|
||||||
|
|
||||||
/** \fn cmph_uint32 jenkins_state_packed_size(jenkins_state_t *state);
|
/** \fn cmph_uint32 jenkins_state_packed_size();
|
||||||
* \brief Return the amount of space needed to pack a jenkins function.
|
* \brief Return the amount of space needed to pack a jenkins function.
|
||||||
* \return the size of the packed function or zero for failures
|
* \return the size of the packed function or zero for failures
|
||||||
*/
|
*/
|
||||||
|
327
src/select.c
Normal file
327
src/select.c
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include "select_lookup_tables.h"
|
||||||
|
#include "select.h"
|
||||||
|
|
||||||
|
//#define DEBUG
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
#ifndef STEP_SELECT_TABLE
|
||||||
|
#define STEP_SELECT_TABLE 128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NBITS_STEP_SELECT_TABLE
|
||||||
|
#define NBITS_STEP_SELECT_TABLE 7
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MASK_STEP_SELECT_TABLE
|
||||||
|
#define MASK_STEP_SELECT_TABLE 0x7f // 0x7f = 127
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline void select_insert_0(cmph_uint32 * buffer)
|
||||||
|
{
|
||||||
|
(*buffer) >>= 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void select_insert_1(cmph_uint32 * buffer)
|
||||||
|
{
|
||||||
|
(*buffer) >>= 1;
|
||||||
|
(*buffer) |= 0x80000000;
|
||||||
|
};
|
||||||
|
|
||||||
|
void select_init(select_t * sel, cmph_uint32 n, cmph_uint32 m)
|
||||||
|
{
|
||||||
|
register cmph_uint32 nbits;
|
||||||
|
register cmph_uint32 vec_size;
|
||||||
|
register cmph_uint32 sel_table_size;
|
||||||
|
sel->n = n;
|
||||||
|
sel->m = m; // n values in the range [0,m-1]
|
||||||
|
|
||||||
|
nbits = sel->n + sel->m;
|
||||||
|
vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
|
||||||
|
sel_table_size = (sel->n >> NBITS_STEP_SELECT_TABLE) + 1; // (sel->n >> NBITS_STEP_SELECT_TABLE) = (sel->n/STEP_SELECT_TABLE)
|
||||||
|
|
||||||
|
sel->bits_vec = (cmph_uint32 *)calloc(vec_size, sizeof(cmph_uint32));
|
||||||
|
|
||||||
|
sel->select_table = (cmph_uint32 *)calloc(sel_table_size, sizeof(cmph_uint32));
|
||||||
|
};
|
||||||
|
|
||||||
|
double select_get_space_usage(select_t * sel)
|
||||||
|
{
|
||||||
|
register cmph_uint32 nbits;
|
||||||
|
register cmph_uint32 vec_size;
|
||||||
|
register cmph_uint32 sel_table_size;
|
||||||
|
register double space_usage;
|
||||||
|
|
||||||
|
nbits = sel->n + sel->m;
|
||||||
|
vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
sel_table_size = (sel->n >> NBITS_STEP_SELECT_TABLE) + 1; // (sel->n >> NBITS_STEP_SELECT_TABLE) = (sel->n/STEP_SELECT_TABLE)
|
||||||
|
|
||||||
|
space_usage = 2 * sizeof(cmph_uint32) * 8; // n and m
|
||||||
|
space_usage += vec_size * sizeof(cmph_uint32) * 8;
|
||||||
|
space_usage += sel_table_size * sizeof(cmph_uint32) * 8;
|
||||||
|
return space_usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void select_destroy(select_t * sel)
|
||||||
|
{
|
||||||
|
free(sel->bits_vec);
|
||||||
|
free(sel->select_table);
|
||||||
|
sel->bits_vec = 0;
|
||||||
|
sel->select_table = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void select_generate_sel_table(select_t * sel)
|
||||||
|
{
|
||||||
|
register cmph_uint8 * bits_table = (cmph_uint8 *)sel->bits_vec;
|
||||||
|
register cmph_uint32 part_sum, old_part_sum;
|
||||||
|
register cmph_uint32 vec_idx, one_idx, sel_table_idx;
|
||||||
|
|
||||||
|
part_sum = vec_idx = one_idx = sel_table_idx = 0;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
// FABIANO: Should'n it be one_idx >= sel->n
|
||||||
|
if(one_idx >= sel->n)
|
||||||
|
break;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
old_part_sum = part_sum;
|
||||||
|
part_sum += rank_lookup_table[bits_table[vec_idx]];
|
||||||
|
vec_idx++;
|
||||||
|
} while (part_sum <= one_idx);
|
||||||
|
|
||||||
|
sel->select_table[sel_table_idx] = select_lookup_table[bits_table[vec_idx - 1]][one_idx - old_part_sum] + ((vec_idx - 1) << 3); // ((vec_idx - 1) << 3) = ((vec_idx - 1) * 8)
|
||||||
|
one_idx += STEP_SELECT_TABLE ;
|
||||||
|
sel_table_idx++;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void select_generate(select_t * sel, cmph_uint32 * keys_vec)
|
||||||
|
{
|
||||||
|
register cmph_uint32 i, j, idx;
|
||||||
|
cmph_uint32 buffer = 0;
|
||||||
|
|
||||||
|
idx = i = j = 0;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
while(keys_vec[j]==i)
|
||||||
|
{
|
||||||
|
select_insert_1(&buffer);
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
if((idx & 0x1f) == 0 ) // (idx & 0x1f) = idx % 32
|
||||||
|
sel->bits_vec[(idx >> 5) - 1] = buffer; // (idx >> 5) = idx/32
|
||||||
|
j++;
|
||||||
|
|
||||||
|
if(j == sel->n)
|
||||||
|
goto loop_end;
|
||||||
|
|
||||||
|
//assert(keys_vec[j] < keys_vec[j-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i == sel->m)
|
||||||
|
break;
|
||||||
|
|
||||||
|
while(keys_vec[j] > i)
|
||||||
|
{
|
||||||
|
select_insert_0(&buffer);
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
if((idx & 0x1f) == 0 ) // (idx & 0x1f) = idx % 32
|
||||||
|
sel->bits_vec[(idx >> 5) - 1] = buffer; // (idx >> 5) = idx/32
|
||||||
|
i++;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
loop_end:
|
||||||
|
if((idx & 0x1f) != 0 ) // (idx & 0x1f) = idx % 32
|
||||||
|
{
|
||||||
|
buffer >>= 32 - (idx & 0x1f);
|
||||||
|
sel->bits_vec[ (idx - 1) >> 5 ] = buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
select_generate_sel_table(sel);
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline cmph_int32 _select_query(cmph_uint8 * bits_table, cmph_uint32 * select_table, cmph_uint32 one_idx)
|
||||||
|
{
|
||||||
|
register cmph_uint32 vec_bit_idx ,vec_byte_idx;
|
||||||
|
register cmph_uint32 part_sum, old_part_sum;
|
||||||
|
|
||||||
|
vec_bit_idx = select_table[one_idx >> NBITS_STEP_SELECT_TABLE]; // one_idx >> NBITS_STEP_SELECT_TABLE = one_idx/STEP_SELECT_TABLE
|
||||||
|
vec_byte_idx = vec_bit_idx >> 3; // vec_bit_idx / 8
|
||||||
|
|
||||||
|
one_idx &= MASK_STEP_SELECT_TABLE; // one_idx %= STEP_SELECT_TABLE == one_idx &= MASK_STEP_SELECT_TABLE
|
||||||
|
one_idx += rank_lookup_table[bits_table[vec_byte_idx] & ((1 << (vec_bit_idx & 0x7)) - 1)];
|
||||||
|
part_sum = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
old_part_sum = part_sum;
|
||||||
|
part_sum += rank_lookup_table[bits_table[vec_byte_idx]];
|
||||||
|
vec_byte_idx++;
|
||||||
|
|
||||||
|
}while (part_sum <= one_idx);
|
||||||
|
|
||||||
|
return select_lookup_table[bits_table[vec_byte_idx - 1]][one_idx - old_part_sum] + ((vec_byte_idx-1) << 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmph_int32 select_query(select_t * sel, cmph_uint32 one_idx)
|
||||||
|
{
|
||||||
|
return _select_query((cmph_uint8 *)sel->bits_vec, sel->select_table, one_idx);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static inline cmph_int32 _select_next_query(cmph_uint8 * bits_table, cmph_uint32 vec_bit_idx)
|
||||||
|
{
|
||||||
|
register cmph_uint32 vec_byte_idx, one_idx;
|
||||||
|
register cmph_uint32 part_sum, old_part_sum;
|
||||||
|
|
||||||
|
vec_byte_idx = vec_bit_idx >> 3;
|
||||||
|
|
||||||
|
one_idx = rank_lookup_table[bits_table[vec_byte_idx] & ((1 << (vec_bit_idx & 0x7)) - 1)] + 1;
|
||||||
|
part_sum = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
old_part_sum = part_sum;
|
||||||
|
part_sum += rank_lookup_table[bits_table[vec_byte_idx]];
|
||||||
|
vec_byte_idx++;
|
||||||
|
|
||||||
|
}while (part_sum <= one_idx);
|
||||||
|
|
||||||
|
return select_lookup_table[bits_table[(vec_byte_idx - 1)]][(one_idx - old_part_sum)] + ((vec_byte_idx - 1) << 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmph_int32 select_next_query(select_t * sel, cmph_uint32 vec_bit_idx)
|
||||||
|
{
|
||||||
|
return _select_next_query((cmph_uint8 *)sel->bits_vec, vec_bit_idx);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void select_dump(select_t *sel, char **buf, cmph_uint32 *buflen)
|
||||||
|
{
|
||||||
|
register cmph_uint32 nbits = sel->n + sel->m;
|
||||||
|
register cmph_uint32 vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
register cmph_uint32 sel_table_size = (sel->n >> NBITS_STEP_SELECT_TABLE) + 1; // (sel->n >> NBITS_STEP_SELECT_TABLE) = (sel->n/STEP_SELECT_TABLE)
|
||||||
|
register cmph_uint32 pos = 0;
|
||||||
|
|
||||||
|
*buflen = 2*sizeof(cmph_uint32) + vec_size + sel_table_size;
|
||||||
|
|
||||||
|
*buf = (char *)calloc(*buflen, sizeof(char));
|
||||||
|
|
||||||
|
if (!*buf)
|
||||||
|
{
|
||||||
|
*buflen = UINT_MAX;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(*buf, &(sel->n), sizeof(cmph_uint32));
|
||||||
|
pos += sizeof(cmph_uint32);
|
||||||
|
memcpy(*buf + pos, &(sel->m), sizeof(cmph_uint32));
|
||||||
|
pos += sizeof(cmph_uint32);
|
||||||
|
memcpy(*buf + pos, sel->bits_vec, vec_size);
|
||||||
|
pos += vec_size;
|
||||||
|
memcpy(*buf + pos, sel->select_table, sel_table_size);
|
||||||
|
|
||||||
|
DEBUGP("Dumped select structure with size %u bytes\n", *buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void select_load(select_t * sel, const char *buf, cmph_uint32 buflen)
|
||||||
|
{
|
||||||
|
register cmph_uint32 pos = 0;
|
||||||
|
register cmph_uint32 nbits = 0;
|
||||||
|
register cmph_uint32 vec_size = 0;
|
||||||
|
register cmph_uint32 sel_table_size = 0;
|
||||||
|
|
||||||
|
memcpy(&(sel->n), buf, sizeof(cmph_uint32));
|
||||||
|
pos += sizeof(cmph_uint32);
|
||||||
|
memcpy(&(sel->m), buf + pos, sizeof(cmph_uint32));
|
||||||
|
pos += sizeof(cmph_uint32);
|
||||||
|
|
||||||
|
nbits = sel->n + sel->m;
|
||||||
|
vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
sel_table_size = (sel->n >> NBITS_STEP_SELECT_TABLE) + 1; // (sel->n >> NBITS_STEP_SELECT_TABLE) = (sel->n/STEP_SELECT_TABLE)
|
||||||
|
|
||||||
|
if(sel->bits_vec) free(sel->bits_vec);
|
||||||
|
sel->bits_vec = (cmph_uint32 *)calloc(vec_size, sizeof(cmph_uint32));
|
||||||
|
|
||||||
|
if(sel->select_table) free(sel->select_table);
|
||||||
|
sel->select_table = (cmph_uint32 *)calloc(sel_table_size, sizeof(cmph_uint32));
|
||||||
|
|
||||||
|
memcpy(sel->bits_vec, buf + pos, vec_size);
|
||||||
|
pos += vec_size;
|
||||||
|
memcpy(sel->select_table, buf + pos, sel_table_size);
|
||||||
|
|
||||||
|
DEBUGP("Loaded select structure with size %u bytes\n", buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn void select_pack(select_t *sel, void *sel_packed);
|
||||||
|
* \brief Support the ability to pack a select structure function into a preallocated contiguous memory space pointed by sel_packed.
|
||||||
|
* \param sel points to the select structure
|
||||||
|
* \param sel_packed pointer to the contiguous memory area used to store the select structure. The size of sel_packed must be at least @see select_packed_size
|
||||||
|
*/
|
||||||
|
void select_pack(select_t *sel, void *sel_packed)
|
||||||
|
{
|
||||||
|
if (sel && sel_packed)
|
||||||
|
{
|
||||||
|
char *buf = NULL;
|
||||||
|
cmph_uint32 buflen = 0;
|
||||||
|
select_dump(sel, &buf, &buflen);
|
||||||
|
memcpy(sel_packed, buf, buflen);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn cmph_uint32 select_packed_size(select_t *sel);
|
||||||
|
* \brief Return the amount of space needed to pack a select structure.
|
||||||
|
* \return the size of the packed select structure or zero for failures
|
||||||
|
*/
|
||||||
|
cmph_uint32 select_packed_size(select_t *sel)
|
||||||
|
{
|
||||||
|
register cmph_uint32 nbits = sel->n + sel->m;
|
||||||
|
register cmph_uint32 vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
register cmph_uint32 sel_table_size = (sel->n >> NBITS_STEP_SELECT_TABLE) + 1; // (sel->n >> NBITS_STEP_SELECT_TABLE) = (sel->n/STEP_SELECT_TABLE)
|
||||||
|
return 2*sizeof(cmph_uint32) + vec_size + sel_table_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn cmph_int32 select_query_packed(void * sel_packed, cmph_uint32 idx);
|
||||||
|
* \param sel_packed is a pointer to a contiguous memory area
|
||||||
|
* \param idx is the rank for which we want to calculate the inverse function select
|
||||||
|
* \return an integer that represents the select value of rank idx.
|
||||||
|
*/
|
||||||
|
cmph_int32 select_query_packed(void * sel_packed, cmph_uint32 one_idx)
|
||||||
|
{
|
||||||
|
register cmph_uint32 *ptr = (cmph_uint32 *)sel_packed;
|
||||||
|
register cmph_uint32 n = *ptr++;
|
||||||
|
register cmph_uint32 m = *ptr++;
|
||||||
|
register cmph_uint32 nbits = n + m;
|
||||||
|
register cmph_uint32 vec_size = (nbits + 31) >> 5; // (nbits + 31) >> 5 = (nbits + 31)/32
|
||||||
|
register cmph_uint8 * bits_vec = (cmph_uint8 *)ptr;
|
||||||
|
register cmph_uint32 * select_table = ptr + vec_size;
|
||||||
|
|
||||||
|
return _select_query(bits_vec, select_table, one_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn cmph_int32 select_next_query_packed(void * sel_packed, cmph_uint32 vec_bit_idx);
|
||||||
|
* \param sel_packed is a pointer to a contiguous memory area
|
||||||
|
* \param vec_bit_idx is a value prior computed by @see select_query_packed
|
||||||
|
* \return an integer that represents the next select value greater than @see vec_bit_idx.
|
||||||
|
*/
|
||||||
|
cmph_int32 select_next_query_packed(void * sel_packed, cmph_uint32 vec_bit_idx)
|
||||||
|
{
|
||||||
|
register cmph_uint8 * bits_vec = (cmph_uint8 *)sel_packed;
|
||||||
|
bits_vec += 8; // skipping n and m
|
||||||
|
return _select_next_query(bits_vec, vec_bit_idx);
|
||||||
|
}
|
61
src/select.h
Normal file
61
src/select.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#ifndef SELECT_h
|
||||||
|
#define SELECT_h
|
||||||
|
|
||||||
|
#include "cmph_types.h"
|
||||||
|
|
||||||
|
struct _select_t
|
||||||
|
{
|
||||||
|
cmph_uint32 n,m;
|
||||||
|
cmph_uint32 * bits_vec;
|
||||||
|
cmph_uint32 * select_table;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct _select_t select_t;
|
||||||
|
|
||||||
|
void select_init(select_t * sel, cmph_uint32 n, cmph_uint32 m);
|
||||||
|
|
||||||
|
void select_destroy(select_t * sel);
|
||||||
|
|
||||||
|
void select_generate(select_t * sel, cmph_uint32 * keys_vec);
|
||||||
|
|
||||||
|
cmph_int32 select_query(select_t * sel, cmph_uint32 one_idx);
|
||||||
|
|
||||||
|
cmph_int32 select_next_query(select_t * sel, cmph_uint32 vec_bit_idx);
|
||||||
|
|
||||||
|
double select_get_space_usage(select_t * sel);
|
||||||
|
|
||||||
|
void select_dump(select_t *sel, char **buf, cmph_uint32 *buflen);
|
||||||
|
|
||||||
|
void select_load(select_t * sel, const char *buf, cmph_uint32 buflen);
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn void select_pack(select_t *sel, void *sel_packed);
|
||||||
|
* \brief Support the ability to pack a select structure function into a preallocated contiguous memory space pointed by sel_packed.
|
||||||
|
* \param sel points to the select structure
|
||||||
|
* \param sel_packed pointer to the contiguous memory area used to store the select structure. The size of sel_packed must be at least @see select_packed_size
|
||||||
|
*/
|
||||||
|
void select_pack(select_t *sel, void *sel_packed);
|
||||||
|
|
||||||
|
/** \fn cmph_uint32 select_packed_size(select_t *sel);
|
||||||
|
* \brief Return the amount of space needed to pack a select structure.
|
||||||
|
* \return the size of the packed select structure or zero for failures
|
||||||
|
*/
|
||||||
|
cmph_uint32 select_packed_size(select_t *sel);
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn cmph_int32 select_query_packed(void * sel_packed, cmph_uint32 idx);
|
||||||
|
* \param sel_packed is a pointer to a contiguous memory area
|
||||||
|
* \param one_idx is the rank for which we want to calculate the inverse function select
|
||||||
|
* \return an integer that represents the select value of rank idx.
|
||||||
|
*/
|
||||||
|
cmph_int32 select_query_packed(void * sel_packed, cmph_uint32 one_idx);
|
||||||
|
|
||||||
|
|
||||||
|
/** \fn cmph_int32 select_next_query_packed(void * sel_packed, cmph_uint32 vec_bit_idx);
|
||||||
|
* \param sel_packed is a pointer to a contiguous memory area
|
||||||
|
* \param vec_bit_idx is a value prior computed by @see select_query_packed
|
||||||
|
* \return an integer that represents the next select value greater than @see vec_bit_idx.
|
||||||
|
*/
|
||||||
|
cmph_int32 select_next_query_packed(void * sel_packed, cmph_uint32 vec_bit_idx);
|
||||||
|
|
||||||
|
#endif
|
170
src/select_lookup_tables.h
Normal file
170
src/select_lookup_tables.h
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
#ifndef SELECT_LOOKUP_TABLES
|
||||||
|
#define SELECT_LOOKUP_TABLES
|
||||||
|
|
||||||
|
#include "cmph_types.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
rank_lookup_table[i] simply gives the number of bits set to one in the byte of value i.
|
||||||
|
For example if i = 01010101 in binary then we have :
|
||||||
|
rank_lookup_table[i] = 4
|
||||||
|
*/
|
||||||
|
|
||||||
|
static cmph_uint8 rank_lookup_table[256] ={
|
||||||
|
0 , 1 , 1 , 2 , 1 , 2 , 2 , 3 , 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4
|
||||||
|
, 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 , 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5
|
||||||
|
, 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 , 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 , 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6 , 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7
|
||||||
|
, 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 , 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6 , 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7
|
||||||
|
, 2 , 3 , 3 , 4 , 3 , 4 , 4 , 5 , 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6
|
||||||
|
, 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6 , 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7
|
||||||
|
, 3 , 4 , 4 , 5 , 4 , 5 , 5 , 6 , 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7
|
||||||
|
, 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7 , 5 , 6 , 6 , 7 , 6 , 7 , 7 , 8
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
select_lookup_table[i][j] simply gives the index of the j'th bit set to one in the byte of value i.
|
||||||
|
For example if i=01010101 in binary then we have :
|
||||||
|
select_lookup_table[i][0] = 0, the first bit set to one is at position 0
|
||||||
|
select_lookup_table[i][1] = 2, the second bit set to one is at position 2
|
||||||
|
select_lookup_table[i][2] = 4, the third bit set to one is at position 4
|
||||||
|
select_lookup_table[i][3] = 6, the fourth bit set to one is at position 6
|
||||||
|
select_lookup_table[i][4] = 255, there is no more than 4 bits set to one in i, so we return escape value 255.
|
||||||
|
*/
|
||||||
|
static cmph_uint8 select_lookup_table[256][8]={
|
||||||
|
{ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 4 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 255 , 255 , 255 } ,
|
||||||
|
{ 5 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 5 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 5 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 5 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 5 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 5 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 5 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 5 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 5 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 5 , 255 , 255 , 255 } ,
|
||||||
|
{ 4 , 5 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 5 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 5 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 5 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 5 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 5 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 5 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 5 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 5 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 5 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 5 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 5 , 255 , 255 } ,
|
||||||
|
{ 6 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 6 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 6 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 6 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 4 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 6 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 6 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 6 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 6 , 255 , 255 } ,
|
||||||
|
{ 5 , 6 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 5 , 6 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 5 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 5 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 5 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 5 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 5 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 5 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 5 , 6 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 5 , 6 , 255 , 255 } ,
|
||||||
|
{ 4 , 5 , 6 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 5 , 6 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 5 , 6 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 5 , 6 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 5 , 6 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 5 , 6 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 5 , 6 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 5 , 6 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 5 , 6 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 5 , 6 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 5 , 6 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 255 } ,
|
||||||
|
{ 7 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 4 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 7 , 255 , 255 } ,
|
||||||
|
{ 5 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 5 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 5 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 5 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 5 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 5 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 5 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 5 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 5 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 5 , 7 , 255 , 255 } ,
|
||||||
|
{ 4 , 5 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 5 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 5 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 5 , 7 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 5 , 7 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 5 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 5 , 7 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 5 , 7 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 5 , 7 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 5 , 7 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 5 , 7 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 5 , 7 , 255 } ,
|
||||||
|
{ 6 , 7 , 255 , 255 , 255 , 255 , 255 , 255 } , { 0 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 1 , 6 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 2 , 6 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 2 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 3 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 3 , 6 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 3 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 3 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 3 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 4 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 4 , 6 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 4 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 4 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 4 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 3 , 4 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 3 , 4 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 3 , 4 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 6 , 7 , 255 , 255 , 255 } , { 0 , 2 , 3 , 4 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 6 , 7 , 255 , 255 } , { 0 , 1 , 2 , 3 , 4 , 6 , 7 , 255 } ,
|
||||||
|
{ 5 , 6 , 7 , 255 , 255 , 255 , 255 , 255 } , { 0 , 5 , 6 , 7 , 255 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 5 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 1 , 5 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 2 , 5 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 2 , 5 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 2 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 3 , 5 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 3 , 5 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 3 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 2 , 3 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 2 , 3 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 5 , 6 , 7 , 255 , 255 } , { 0 , 1 , 2 , 3 , 5 , 6 , 7 , 255 } ,
|
||||||
|
{ 4 , 5 , 6 , 7 , 255 , 255 , 255 , 255 } , { 0 , 4 , 5 , 6 , 7 , 255 , 255 , 255 } ,
|
||||||
|
{ 1 , 4 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 1 , 4 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 2 , 4 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 2 , 4 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 1 , 2 , 4 , 5 , 6 , 7 , 255 , 255 } , { 0 , 1 , 2 , 4 , 5 , 6 , 7 , 255 } ,
|
||||||
|
{ 3 , 4 , 5 , 6 , 7 , 255 , 255 , 255 } , { 0 , 3 , 4 , 5 , 6 , 7 , 255 , 255 } ,
|
||||||
|
{ 1 , 3 , 4 , 5 , 6 , 7 , 255 , 255 } , { 0 , 1 , 3 , 4 , 5 , 6 , 7 , 255 } ,
|
||||||
|
{ 2 , 3 , 4 , 5 , 6 , 7 , 255 , 255 } , { 0 , 2 , 3 , 4 , 5 , 6 , 7 , 255 } ,
|
||||||
|
{ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 255 } , { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } };
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
noinst_PROGRAMS = graph_tests packed_mphf_tests mphf_tests
|
noinst_PROGRAMS = graph_tests packed_mphf_tests mphf_tests select_tests
|
||||||
|
|
||||||
INCLUDES = -I../src/
|
INCLUDES = -I../src/
|
||||||
|
|
||||||
@ -10,3 +10,6 @@ packed_mphf_tests_LDADD = ../src/libcmph.la
|
|||||||
|
|
||||||
mphf_tests_SOURCES = mphf_tests.c
|
mphf_tests_SOURCES = mphf_tests.c
|
||||||
mphf_tests_LDADD = ../src/libcmph.la
|
mphf_tests_LDADD = ../src/libcmph.la
|
||||||
|
|
||||||
|
select_tests_SOURCES = select_tests.c
|
||||||
|
select_tests_LDADD = ../src/libcmph.la
|
||||||
|
96
tests/select_tests.c
Normal file
96
tests/select_tests.c
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#include "../src/select.h"
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
#include "../src/debug.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static inline void print_values(select_t * sel)
|
||||||
|
{
|
||||||
|
register cmph_uint32 index;
|
||||||
|
|
||||||
|
index = select_query(sel, 0);
|
||||||
|
fprintf(stderr, "Index[0]\t= %u\n", index - 0);
|
||||||
|
|
||||||
|
index = select_next_query(sel, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query(sel, 1);
|
||||||
|
fprintf(stderr, "Index[1]\t= %u\n", index - 1);
|
||||||
|
|
||||||
|
index = select_next_query(sel, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query(sel, 2);
|
||||||
|
fprintf(stderr, "Index[2]\t= %u\n", index - 2);
|
||||||
|
|
||||||
|
index = select_next_query(sel, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query(sel, 3);
|
||||||
|
fprintf(stderr, "Index[3]\t= %u\n", index - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void print_values_packed(char * sel_packed)
|
||||||
|
{
|
||||||
|
register cmph_uint32 index;
|
||||||
|
|
||||||
|
index = select_query_packed(sel_packed, 0);
|
||||||
|
fprintf(stderr, "Index[0]\t= %u\n", index - 0);
|
||||||
|
|
||||||
|
index = select_next_query_packed(sel_packed, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query_packed(sel_packed, 1);
|
||||||
|
fprintf(stderr, "Index[1]\t= %u\n", index - 1);
|
||||||
|
|
||||||
|
index = select_next_query_packed(sel_packed, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query_packed(sel_packed, 2);
|
||||||
|
fprintf(stderr, "Index[2]\t= %u\n", index - 2);
|
||||||
|
|
||||||
|
index = select_next_query_packed(sel_packed, index);
|
||||||
|
fprintf(stderr, "Next Index\t= %u\n", index);
|
||||||
|
|
||||||
|
index = select_query_packed(sel_packed, 3);
|
||||||
|
fprintf(stderr, "Index[3]\t= %u\n", index - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
select_t sel;
|
||||||
|
cmph_uint32 n = 4;
|
||||||
|
cmph_uint32 keys_vec[4] = {0,1,2,3};
|
||||||
|
cmph_uint32 m = keys_vec[3];
|
||||||
|
char *buf = NULL;
|
||||||
|
cmph_uint32 buflen = 0;
|
||||||
|
char * select_packed = NULL;
|
||||||
|
cmph_uint32 select_pack_size = 0;
|
||||||
|
|
||||||
|
select_init(&sel, n, m);
|
||||||
|
select_generate(&sel, keys_vec);
|
||||||
|
fprintf(stderr, "Space usage = %f\n", select_get_space_usage(&sel));
|
||||||
|
print_values(&sel);
|
||||||
|
|
||||||
|
fprintf(stderr, "Dumping select structure\n");
|
||||||
|
select_dump(&sel, &buf, &buflen);
|
||||||
|
|
||||||
|
select_destroy(&sel);
|
||||||
|
fprintf(stderr, "Loading select structure\n");
|
||||||
|
|
||||||
|
select_load(&sel, buf, buflen);
|
||||||
|
print_values(&sel);
|
||||||
|
free(buf);;
|
||||||
|
|
||||||
|
select_pack_size = select_packed_size(&sel);
|
||||||
|
|
||||||
|
select_packed = (char *) calloc(select_pack_size, sizeof(char));
|
||||||
|
select_pack(&sel, select_packed);
|
||||||
|
|
||||||
|
fprintf(stderr, "Querying the packed select structure\n");
|
||||||
|
print_values_packed(select_packed);
|
||||||
|
|
||||||
|
free(select_packed);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user