Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cpp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CXXFLAGS=-Wall -MMD -O3
CFLAGS=-Wall -MMD -O3
all: gcs

-include *.d

GCS_OBJECTS = main.o gcs.o md5.o

gcs: $(GCS_OBJECTS)
g++ $(LDFLAGS) $(GCS_OBJECTS) -o $@
clean:
rm -f *~ *.o *.d gcs


12 changes: 8 additions & 4 deletions cpp/gcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
#include <algorithm>
#include <assert.h>

#define BITMASK(n) ((1 << (n)) - 1)
inline uint64_t BITMASK(unsigned int n)
{
assert(n < 63);
return ((1ULL << (n)) - 1ULL);
}


static uint32_t gcs_hash(const void *data, int size, int N, int P)
static uint32_t gcs_hash(const void *data, int size, unsigned int N, unsigned int P)
{
unsigned char digest[16];
MD5Context ctx;
Expand Down Expand Up @@ -72,7 +76,7 @@ class BitWriter
BitWriter(std::ostream &_f)
: f(_f), accum(0), n(0) {}

void write(int nbits, unsigned value)
void write(int nbits, uint64_t value)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you need to force 64bit here even for 32bit systems?

{
assert(nbits >= 0);
while (nbits)
Expand Down Expand Up @@ -136,7 +140,7 @@ class GolombEncoder
};


GCSBuilder::GCSBuilder(int _n, int _p)
GCSBuilder::GCSBuilder(unsigned int _n, unsigned int _p)
: N(_n), P(_p)
{
assert(N <= ~(hash_t)0 / P);
Expand Down
7 changes: 3 additions & 4 deletions cpp/gcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ typedef uint32_t hash_t;

class GCSBuilder
{
int N, P;
unsigned int N, P;
std::vector<hash_t> values;

public:
GCSBuilder(int N, int P);
GCSBuilder(unsigned int N, unsigned int P);
void add(const void *data, int size);
void finalize(std::ostream &f);
};

class GCSQuery
{
int N, P;
unsigned int N, P;
std::istream &f;
uint8_t *gcs;
int gcs_len;
Expand All @@ -56,6 +56,5 @@ class GCSQuery
bool query(const void *data, int size);
};


#endif /* GCS_H */

2 changes: 0 additions & 2 deletions cpp/make.sh

This file was deleted.

1 change: 0 additions & 1 deletion cpp/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

static void byteReverse(unsigned char *buf, unsigned longs)
{
uint32 t;
do {
*(uint32*)buf = O32_HOST_TO_LE(*(uint32*)buf);
buf += 4;
Expand Down