-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: modernize the project * fixes * fixes * no need for verbose * adding shared library * simplifying * fix: don't change the lib name and remove deprecated functions --------- Co-authored-by: Daniel Lemire <[email protected]>
- Loading branch information
Showing
9 changed files
with
199 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,35 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
cmake_minimum_required(VERSION 3.5) | ||
project(redis-roaring) | ||
set (CMAKE_C_STANDARD 11) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Werror") | ||
set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
set(DEPS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/deps) | ||
set(TEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tests) | ||
set(ENABLE_ROARING_TESTS OFF) | ||
set(CROARING_PATH ${DEPS_PATH}/CRoaring) | ||
add_subdirectory(${CROARING_PATH} EXCLUDE_FROM_ALL) | ||
option(DISABLE_TESTS "disables tests in hiredis" ON) | ||
option(BUILD_SHARED_LIBS "use shared libraries" OFF) | ||
set(HIREDIS_PATH ${DEPS_PATH}/hiredis) | ||
set(SDS_PATH ${DEPS_PATH}/sds) | ||
#set(CMAKE_C_FLAGS_RELEASE "") # removes -NDEBUG | ||
set(CMAKE_BUILD_TYPE Debug) | ||
|
||
link_directories(${HIREDIS_PATH}) | ||
include_directories(${CROARING_PATH}) | ||
include_directories(${HIREDIS_PATH}) | ||
include_directories(${SDS_PATH}) | ||
add_subdirectory(${HIREDIS_PATH} EXCLUDE_FROM_ALL) | ||
include_directories(${SRC_PATH}) | ||
enable_testing() | ||
|
||
####### unit tests ####### | ||
message(STATUS "Compiling unit tests") | ||
|
||
set(UNIT_FILES | ||
${SRC_PATH}/data-structure.c | ||
${SRC_PATH}/roaring.c | ||
${TEST_PATH}/unit.c) | ||
|
||
add_executable(unit ${UNIT_FILES}) | ||
target_link_libraries(unit) | ||
add_executable(unit ${SRC_PATH}/data-structure.c ${TEST_PATH}/unit.c) | ||
target_link_libraries(unit roaring::roaring) | ||
add_test(NAME unit_tests COMMAND unit) | ||
|
||
####### performance tests ####### | ||
message(STATUS "Compiling performance tests") | ||
|
||
set(PERFORMANCE_FILES ${TEST_PATH}/performance.c) | ||
|
||
add_executable(performance ${PERFORMANCE_FILES}) | ||
target_link_libraries(performance libhiredis.a) | ||
target_link_libraries(performance m) | ||
add_executable(performance ${TEST_PATH}/performance.c) | ||
set (CROARING_BENCHMARK_DATA_DIR "${CROARING_PATH}/benchmarks/realdata/") | ||
target_compile_definitions(performance PRIVATE CROARING_BENCHMARK_DATA_DIR="${CROARING_BENCHMARK_DATA_DIR}") | ||
target_link_libraries(performance m roaring::roaring hiredis::hiredis) | ||
add_test(NAME performance_tests COMMAND performance) | ||
|
||
####### redis module ####### | ||
message(STATUS "Compiling redis module") | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(SOURCE_FILES ${SRC_PATH}/redis-roaring.c | ||
${SRC_PATH}/data-structure.c | ||
${SDS_PATH}/sds.c) | ||
add_library(redis-roaring SHARED ${SOURCE_FILES}) | ||
target_link_libraries(redis-roaring) | ||
set(REDIS_ROARING_SOURCE_FILES ${SRC_PATH}/redis-roaring.c | ||
${SRC_PATH}/data-structure.c) | ||
add_library(redis-roaring SHARED ${REDIS_ROARING_SOURCE_FILES}) | ||
|
||
target_link_libraries(redis-roaring roaring::roaring hiredis::hiredis) |
Submodule hiredis
updated
65 files
Submodule redis
updated
from 58f79e to d2c8a4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#ifndef BITMAPSFROMTEXTFILES_H_ | ||
#define BITMAPSFROMTEXTFILES_H_ | ||
#ifndef _GNU_SOURCE | ||
#define _GNU_SOURCE | ||
#endif | ||
#include <dirent.h> | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
/*********************************/ | ||
/******************************** | ||
* General functions to load up bitmaps from text files. | ||
* Except format: comma-separated integers. | ||
*******************************/ | ||
/*********************************/ | ||
|
||
/** | ||
* Read the content of a file to a char array. Caller is | ||
* responsible for memory de-allocation. | ||
* Returns NULL on error. | ||
* | ||
* (If the individual files are small, this function is | ||
* a good idea.) | ||
*/ | ||
static char *read_file(const char *filename) { | ||
FILE *fp = fopen(filename, "r"); | ||
if (!fp) { | ||
printf("Could not open file %s\n", filename); | ||
return NULL; | ||
} | ||
|
||
fseek(fp, 0, SEEK_END); | ||
size_t size = (size_t)ftell(fp); | ||
rewind(fp); | ||
char *answer = (char *)malloc(size + 1); | ||
if (!answer) { | ||
fclose(fp); | ||
return NULL; | ||
} | ||
if (fread(answer, size, 1, fp) != 1) { | ||
free(answer); | ||
return NULL; | ||
} | ||
answer[size] = '\0'; | ||
fclose(fp); | ||
return answer; | ||
} | ||
|
||
/** | ||
* Given a file made of comma-separated integers, | ||
* read it all and generate an array of integers. | ||
* The caller is responsible for memory de-allocation. | ||
*/ | ||
static uint32_t *read_integer_file(const char *filename, size_t *howmany) { | ||
char *buffer = read_file(filename); | ||
if (buffer == NULL) return NULL; | ||
|
||
size_t howmanyints = 1; | ||
size_t i1 = 0; | ||
for (; buffer[i1] != '\0'; i1++) { | ||
if (buffer[i1] == ',') ++howmanyints; | ||
} | ||
|
||
uint32_t *answer = (uint32_t *)malloc(howmanyints * sizeof(uint32_t)); | ||
if (answer == NULL) return NULL; | ||
size_t pos = 0; | ||
for (size_t i = 0; (i < i1) && (buffer[i] != '\0'); i++) { | ||
uint32_t currentint; | ||
while ((buffer[i] < '0') || (buffer[i] > '9')) { | ||
i++; | ||
if (buffer[i] == '\0') goto END; | ||
} | ||
currentint = (uint32_t)(buffer[i] - '0'); | ||
i++; | ||
for (; (buffer[i] >= '0') && (buffer[i] <= '9'); i++) | ||
currentint = currentint * 10 + (uint32_t)(buffer[i] - '0'); | ||
answer[pos++] = currentint; | ||
} | ||
END: | ||
if (pos != howmanyints) { | ||
printf("unexpected number of integers! %d %d \n", (int)pos, | ||
(int)howmanyints); | ||
} | ||
*howmany = pos; | ||
free(buffer); | ||
return answer; | ||
} | ||
|
||
/** | ||
* Does the file filename ends with the given extension. | ||
*/ | ||
static bool hasExtension(const char *filename, const char *extension) { | ||
const char *ext = strrchr(filename, '.'); | ||
return (ext && !strcmp(ext, extension)); | ||
} | ||
|
||
/** | ||
* read all (count) integer files in a directory. Caller is responsible | ||
* for memory de-allocation. In case of error, a NULL is returned. | ||
*/ | ||
static uint32_t **read_all_integer_files(const char *dirname, | ||
const char *extension, | ||
size_t **howmany, size_t *count) { | ||
struct dirent **entry_list; | ||
|
||
int c = scandir(dirname, &entry_list, 0, alphasort); | ||
if (c < 0) return NULL; | ||
size_t truec = 0; | ||
for (int i = 0; i < c; i++) { | ||
if (hasExtension(entry_list[i]->d_name, extension)) ++truec; | ||
} | ||
*count = truec; | ||
*howmany = (size_t *)malloc(sizeof(size_t) * (*count)); | ||
uint32_t **answer = (uint32_t **)malloc(sizeof(uint32_t *) * (*count)); | ||
size_t dirlen = strlen(dirname); | ||
char *modifdirname = (char *)dirname; | ||
if (modifdirname[dirlen - 1] != '/') { | ||
modifdirname = (char *)malloc(dirlen + 2); | ||
strcpy(modifdirname, dirname); | ||
modifdirname[dirlen] = '/'; | ||
modifdirname[dirlen + 1] = '\0'; | ||
dirlen++; | ||
} | ||
for (size_t i = 0, pos = 0; i < (size_t)c; | ||
i++) { /* formerly looped while i < *count */ | ||
if (!hasExtension(entry_list[i]->d_name, extension)) continue; | ||
size_t filelen = strlen(entry_list[i]->d_name); | ||
char *fullpath = (char *)malloc(dirlen + filelen + 1); | ||
strcpy(fullpath, modifdirname); | ||
strcpy(fullpath + dirlen, entry_list[i]->d_name); | ||
answer[pos] = read_integer_file(fullpath, &((*howmany)[pos])); | ||
pos++; | ||
free(fullpath); | ||
} | ||
if (modifdirname != dirname) { | ||
free(modifdirname); | ||
} | ||
for (int i = 0; i < c; ++i) free(entry_list[i]); | ||
free(entry_list); | ||
return answer; | ||
} | ||
|
||
#endif /* BITMAPSFROMTEXTFILES_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters