Compiles with clang.

This commit is contained in:
Davi de Castro Reis 2012-06-01 17:49:00 -03:00
parent 59bb0dac72
commit 0c13ae5fa4
23 changed files with 251 additions and 83 deletions

View File

@ -1,9 +1,9 @@
TESTS = $(check_PROGRAMS)
check_PROGRAMS = seeded_hash_test mph_bits_test hollow_iterator_test mph_map_test mph_index_test trigraph_test map_tester_test
check_PROGRAMS = seeded_hash_test mph_bits_test hollow_iterator_test mph_map_test mph_index_test trigraph_test map_tester_test string_util_test
noinst_PROGRAMS = bm_index bm_map
bin_PROGRAMS = cxxmph
lib_LTLIBRARIES = libcxxmph.la
libcxxmph_la_SOURCES = MurmurHash3.h MurmurHash3.cpp trigragh.h trigraph.cc mph_bits.h mph_bits.cc mph_index.h mph_index.cc seeded_hash.h stringpiece.h benchmark.h benchmark.cc
libcxxmph_la_SOURCES = MurmurHash3.h MurmurHash3.cpp trigragh.h trigraph.cc mph_bits.h mph_bits.cc mph_index.h mph_index.cc seeded_hash.h stringpiece.h benchmark.h benchmark.cc string_util.cc
libcxxmph_la_LDFLAGS = -version-info 0:0:0
cxxmph_includedir = $(includedir)/cxxmph/
cxxmph_include_HEADERS = mph_map.h mph_index.h MurmurHash3.h trigraph.h seeded_hash.h stringpiece.h hollow_iterator.h
@ -34,5 +34,8 @@ seeded_hash_test_LDADD = libcxxmph.la
mph_bits_test_SOURCES = mph_bits_test.cc
mph_bits_test_LDADD = libcxxmph.la
string_util_test_SOURCES = string_util_test.cc
string_util_test_LDADD = libcxxmph.la
map_tester_test_SOURCES = map_tester.cc map_tester_test.cc

View File

@ -44,10 +44,12 @@ class BM_MPHIndexSearch : public SearchUrlsBenchmark {
BM_MPHIndexSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
virtual void Run() {
uint64_t sum = 0;
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto idx = index_.index(*it);
// Collision check to be fair with STL
if (strcmp(urls_[idx].c_str(), it->data()) != 0) idx = -1;
sum += idx;
}
}
protected:
@ -65,10 +67,12 @@ class BM_CmphIndexSearch : public SearchUrlsBenchmark {
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
~BM_CmphIndexSearch() { if (index_) cmph_destroy(index_); }
virtual void Run() {
uint64_t sum = 0;
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto idx = cmph_search(index_, it->data(), it->length());
// Collision check to be fair with STL
if (strcmp(urls_[idx].c_str(), it->data()) != 0) idx = -1;
sum += idx;
}
}
protected:
@ -114,8 +118,10 @@ class BM_STLIndexSearch : public SearchUrlsBenchmark {
BM_STLIndexSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
virtual void Run() {
uint64_t sum = 0;
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto idx = index_.find(*it);
sum += idx->second;
}
}
protected:

View File

@ -1,5 +1,5 @@
#include <string>
#include <tr1/unordered_map>
#include <unordered_map>
#include "bm_common.h"
#include "mph_map.h"

View File

@ -1,8 +1,4 @@
#include "map_tester.h"
namespace cxxxmph {
MapTester::MapTester() {}
MapTester::~MapTester() {}
}

View File

@ -7,15 +7,18 @@
#include <vector>
#include <unordered_map>
#include "string_util.h"
namespace cxxmph {
using namespace std;
// template <template <class K, class V> class unordered_map> >
template <template<typename...> class map_type>
class MapTester {
public:
MapTester();
~MapTester();
MapTester() {}
~MapTester() {}
bool Run(string* errors) const {
string e;
if (!small_insert()) e += "small insert failed\n";
@ -27,26 +30,26 @@ class MapTester {
return !e.empty();
}
static bool small_insert() {
unordered_map<int64_t, int64_t> m;
map_type<int64_t, int64_t> m;
// Start counting from 1 to not touch default constructed value bugs
for (int i = 1; i < 12; ++i) m.insert(make_pair(i, i));
return m.size() == 11;
}
static bool large_insert() {
unordered_map<int64_t, int64_t> m;
map_type<int64_t, int64_t> m;
// Start counting from 1 to not touch default constructed value bugs
for (int i = 1; i < 12 * 256 * 256; ++i) m.insert(make_pair(i, i));
return m.size() == 12 * 256 * 256 - 1;
}
static bool small_search() {
unordered_map<int64_t, int64_t> m;
map_type<int64_t, int64_t> m;
// Start counting from 1 to not touch default constructed value bugs
for (int i = 1; i < 12; ++i) m.insert(make_pair(i, i));
for (int i = 1; i < 12; ++i) if (m.find(i) == m.end()) return false;
return true;
}
static bool default_search() {
unordered_map<int64_t, int64_t> m;
map_type<int64_t, int64_t> m;
if (m.find(0) != m.end()) return false;
for (int i = 1; i < 256; ++i) m.insert(make_pair(i, i));
if (m.find(0) != m.end()) return false;
@ -56,7 +59,7 @@ class MapTester {
}
static bool large_search() {
int nkeys = 10 * 1000;
unordered_map<int64_t, int64_t> m;
map_type<int64_t, int64_t> m;
for (int i = 0; i < nkeys; ++i) m.insert(make_pair(i, i));
for (int i = 0; i < nkeys; ++i) if (m.find(i) == m.end()) return false;
return true;
@ -66,10 +69,10 @@ class MapTester {
vector<string> keys;
for (int i = 0; i < nkeys; ++i) {
char buf[128];
snprintf(buf, sizeof(buf), "%lu", i);
cxxmph::format("%v", i);
keys.push_back(buf);
}
unordered_map<string, int64_t> m;
map_type<string, int64_t> m;
for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i));
for (int i = 0; i < nkeys; ++i) {
auto it = m.find(keys[i]);

23
cxxmph/string_util.cc Normal file
View File

@ -0,0 +1,23 @@
#include "string_util.h"
#include <cassert>
#include <cstdint>
#include <iostream>
#include <string>
using namespace std;
namespace cxxmph {
bool stream_printf(
const std::string& format_string, uint32_t offset, std::ostream* out) {
if (offset == format_string.length()) return true;
assert(offset < format_string.length());
cerr << "length:" << format_string.length() << endl;
cerr << "offset:" << offset << endl;
auto txt = format_string.substr(offset, format_string.length() - offset);
*out << txt;
return true;
}
} // namespace cxxmph

137
cxxmph/string_util.h Normal file
View File

@ -0,0 +1,137 @@
#ifndef __CXXMPH_STRING_UTIL_H__
#define __CXXMPH_STRING_UTIL_H__
// Helper functions for string formatting and terminal output. Should be used
// only for debugging and tests, since performance was not a concern.
// Implemented using variadic templates because it is cool.
//
// Adds the extra format %v to the printf formatting language. Uses the method
// cxxmph::tostr to implement custom printers and fallback to operator
// ostream::operator<< otherwise.
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <vector>
#define CXXMPH_DEBUGLN(fmt) variadic_print(__FILE__, __LINE__, &std::cerr, fmt)
#define CXXMPH_INFOLN(fmt) variadic_print(__FILE__, __LINE__, &std::cout, fmt)
namespace cxxmph {
using std::pair;
using std::string;
using std::ostream;
using std::vector;
template <class T> void tostr(ostream *out, const T& v) {
*out << v;
}
inline void tostr(std::ostream* out, uint8_t v) {
*out << static_cast<uint32_t>(v);
}
template <class V>
inline void tostr(ostream* out, const vector<V>& v) {
*out << "[";
for (uint32_t i = 0; i < v.size(); ++i) {
tostr(out, v[1]);
if (i != v.size() - 1)*out << " ";
}
*out << "]";
}
template <class F, class S>
inline void tostr(ostream* out, const pair<F, S>& v) {
*out << "(";
tostr(out, v.first);
*out << ",";
tostr(out, v.second);
*out << ")";
}
template <typename... Args, class T >
std::string infoln(const std::string& format_string, Args&&... args) {
return stream_printf(format_string, 0, &std::cout, std::forward<Args>(args)...);
}
bool stream_printf(
const std::string& format_string, uint32_t offset, std::ostream* out);
template <bool ispod> struct pod_snprintf {};
template <> struct pod_snprintf<false> {
template <class T>
int operator()(char*, size_t, const char*, const T&) {
return -1;
}
};
template <> struct pod_snprintf<true> {
template <class T>
int operator()(char* str, size_t size, const char* format, const T& v) {
return snprintf(str, size, format, v);
}
};
template <typename T, typename... Args>
bool stream_printf(const std::string& format_string, uint32_t offset,
std::ostream* out, const T& value, Args&&... args) {
auto b = format_string.c_str() + offset;
auto txt = format_string.c_str() + offset;
for (; *txt; ++txt) {
if (*txt == '%') {
if (*(txt + 1) != '%') break;
*out << "%";
return stream_printf(format_string, offset + 2, out, value,
std::forward<Args>(args)...);
}
}
if (txt != b) {
*out << string(b, txt - b);
}
auto fmt = txt + 1;
while (*fmt && *fmt != '%') ++fmt;
if (strncmp(txt, "%v", 2) == 0) {
txt += 2;
tostr(out, value);
if (txt != fmt) *out << string(txt, fmt);
} else {
char buf[256]; // Is this enough?
auto n = pod_snprintf<std::is_pod<T>::value>()(
buf, 256, std::string(txt, fmt).c_str(), value);
if (n < 0) return false;
*out << buf;
}
return stream_printf(format_string, fmt - format_string.c_str(), out,
std::forward<Args>(args)...);
}
template <typename... Args>
std::string format(const std::string& format_string, Args&&... args) {
std::ostringstream out;
if (!stream_printf(format_string, 0, &out, std::forward<Args>(args)...)) {
return std::string();
};
return out.str();
}
struct variadic_print {
variadic_print(const std::string& file, uint32_t line, std::ostream* out,
const std::string& format_line)
: file_(file), line_(line), out_(out), format_line_(format_line) {}
template <typename... Args>
void operator()(Args&&... args) {
std::string fancy_format = "%s:%d: ";
fancy_format += format_line_;
stream_printf(fancy_format, 0, out_, std::forward<Args>(args)...);
}
const std::string& file_;
const uint32_t& line_;
std::ostream* out_;
const std::string& format_line_;
};
} // namespace cxxmph
#endif // __CXXMPH_STRING_UTIL_H__

View File

@ -47,7 +47,7 @@ typedef cmph_uint32 * bdz_queue_t;
static void bdz_alloc_queue(bdz_queue_t * queuep, cmph_uint32 nedges)
{
(*queuep)=malloc(nedges*sizeof(cmph_uint32));
(*queuep)=(cmph_uint32 *)malloc(nedges*sizeof(cmph_uint32));
};
static void bdz_free_queue(bdz_queue_t * queue)
{
@ -65,9 +65,9 @@ typedef struct
static void bdz_alloc_graph3(bdz_graph3_t * graph3, cmph_uint32 nedges, cmph_uint32 nvertices)
{
graph3->edges=malloc(nedges*sizeof(bdz_edge_t));
graph3->first_edge=malloc(nvertices*sizeof(cmph_uint32));
graph3->vert_degree=malloc((size_t)nvertices);
graph3->edges=(bdz_edge_t *)malloc(nedges*sizeof(bdz_edge_t));
graph3->first_edge=(cmph_uint32 *)malloc(nvertices*sizeof(cmph_uint32));
graph3->vert_degree=(cmph_uint8 *)malloc((size_t)nvertices);
};
static void bdz_init_graph3(bdz_graph3_t * graph3, cmph_uint32 nedges, cmph_uint32 nvertices)
{
@ -163,7 +163,7 @@ static int bdz_generate_queue(cmph_uint32 nedges, cmph_uint32 nvertices, bdz_que
cmph_uint32 queue_head=0,queue_tail=0;
cmph_uint32 curr_edge;
cmph_uint32 tmp_edge;
cmph_uint8 * marked_edge =malloc((size_t)(nedges >> 3) + 1);
cmph_uint8 * marked_edge = (cmph_uint8 *)malloc((size_t)(nedges >> 3) + 1);
memset(marked_edge, 0, (size_t)(nedges >> 3) + 1);
for(i=0;i<nedges;i++){
@ -424,7 +424,7 @@ static void assigning(bdz_config_data_t *bdz, bdz_graph3_t* graph3, bdz_queue_t
cmph_uint32 nedges=graph3->nedges;
cmph_uint32 curr_edge;
cmph_uint32 v0,v1,v2;
cmph_uint8 * marked_vertices =malloc((size_t)(bdz->n >> 3) + 1);
cmph_uint8 * marked_vertices = (cmph_uint8 *)malloc((size_t)(bdz->n >> 3) + 1);
cmph_uint32 sizeg = (cmph_uint32)ceil(bdz->n/4.0);
bdz->g = (cmph_uint8 *)calloc((size_t)(sizeg), sizeof(cmph_uint8));
memset(marked_vertices, 0, (size_t)(bdz->n >> 3) + 1);
@ -595,7 +595,7 @@ static inline cmph_uint32 rank(cmph_uint32 b, cmph_uint32 * ranktable, cmph_uint
cmph_uint32 bdz_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint32 vertex;
register bdz_data_t *bdz = mphf->data;
register bdz_data_t *bdz = (bdz_data_t *)mphf->data;
cmph_uint32 hl[3];
hash_vector(bdz->hl, key, keylen, hl);
hl[0] = hl[0] % bdz->r;
@ -625,7 +625,7 @@ void bdz_destroy(cmph_t *mphf)
void bdz_pack(cmph_t *mphf, void *packed_mphf)
{
bdz_data_t *data = (bdz_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing hl type
CMPH_HASH hl_type = hash_get_type(data->hl);
@ -681,7 +681,7 @@ cmph_uint32 bdz_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke
{
register cmph_uint32 vertex;
register CMPH_HASH hl_type = *(cmph_uint32 *)packed_mphf;
register CMPH_HASH hl_type = (CMPH_HASH)(*(cmph_uint32 *)packed_mphf);
register cmph_uint8 *hl_ptr = (cmph_uint8 *)(packed_mphf) + 4;
register cmph_uint32 *ranktable = (cmph_uint32*)(hl_ptr + hash_state_packed_size(hl_type));

View File

@ -34,7 +34,7 @@ typedef cmph_uint32 * bdz_ph_queue_t;
static void bdz_ph_alloc_queue(bdz_ph_queue_t * queuep, cmph_uint32 nedges)
{
(*queuep)=malloc(nedges*sizeof(cmph_uint32));
(*queuep)=(cmph_uint32 *)malloc(nedges*sizeof(cmph_uint32));
};
static void bdz_ph_free_queue(bdz_ph_queue_t * queue)
{
@ -52,9 +52,9 @@ typedef struct
static void bdz_ph_alloc_graph3(bdz_ph_graph3_t * graph3, cmph_uint32 nedges, cmph_uint32 nvertices)
{
graph3->edges=malloc(nedges*sizeof(bdz_ph_edge_t));
graph3->first_edge=malloc(nvertices*sizeof(cmph_uint32));
graph3->vert_degree=malloc((size_t)nvertices);
graph3->edges=(bdz_ph_edge_t *)malloc(nedges*sizeof(bdz_ph_edge_t));
graph3->first_edge=(cmph_uint32 *)malloc(nvertices*sizeof(cmph_uint32));
graph3->vert_degree=(cmph_uint8 *)malloc((size_t)nvertices);
};
static void bdz_ph_init_graph3(bdz_ph_graph3_t * graph3, cmph_uint32 nedges, cmph_uint32 nvertices)
{
@ -148,7 +148,7 @@ static int bdz_ph_generate_queue(cmph_uint32 nedges, cmph_uint32 nvertices, bdz_
cmph_uint32 queue_head=0,queue_tail=0;
cmph_uint32 curr_edge;
cmph_uint32 tmp_edge;
cmph_uint8 * marked_edge =malloc((size_t)(nedges >> 3) + 1);
cmph_uint8 * marked_edge =(cmph_uint8 *)malloc((size_t)(nedges >> 3) + 1);
memset(marked_edge, 0, (size_t)(nedges >> 3) + 1);
for(i=0;i<nedges;i++){
@ -381,7 +381,7 @@ static void assigning(bdz_ph_config_data_t *bdz_ph, bdz_ph_graph3_t* graph3, bdz
cmph_uint32 nedges=graph3->nedges;
cmph_uint32 curr_edge;
cmph_uint32 v0,v1,v2;
cmph_uint8 * marked_vertices =malloc((size_t)(bdz_ph->n >> 3) + 1);
cmph_uint8 * marked_vertices = (cmph_uint8 *)malloc((size_t)(bdz_ph->n >> 3) + 1);
cmph_uint32 sizeg = (cmph_uint32)ceil(bdz_ph->n/4.0);
bdz_ph->g = (cmph_uint8 *)calloc((size_t)sizeg, sizeof(cmph_uint8));
memset(marked_vertices, 0, (size_t)(bdz_ph->n >> 3) + 1);
@ -507,7 +507,7 @@ void bdz_ph_load(FILE *f, cmph_t *mphf)
cmph_uint32 bdz_ph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
register bdz_ph_data_t *bdz_ph = mphf->data;
register bdz_ph_data_t *bdz_ph = (bdz_ph_data_t *)mphf->data;
cmph_uint32 hl[3];
register cmph_uint8 byte0, byte1, byte2;
register cmph_uint32 vertex;
@ -547,7 +547,7 @@ void bdz_ph_destroy(cmph_t *mphf)
void bdz_ph_pack(cmph_t *mphf, void *packed_mphf)
{
bdz_ph_data_t *data = (bdz_ph_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing hl type
CMPH_HASH hl_type = hash_get_type(data->hl);
@ -590,7 +590,7 @@ cmph_uint32 bdz_ph_packed_size(cmph_t *mphf)
cmph_uint32 bdz_ph_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register CMPH_HASH hl_type = *(cmph_uint32 *)packed_mphf;
register CMPH_HASH hl_type = (CMPH_HASH)*(cmph_uint32 *)packed_mphf;
register cmph_uint8 *hl_ptr = (cmph_uint8 *)(packed_mphf) + 4;
register cmph_uint8 * ptr = hl_ptr + hash_state_packed_size(hl_type);

View File

@ -44,7 +44,7 @@ void bm_create(CMPH_ALGO algo, int iters) {
cmph_config_t* config = NULL;
cmph_t* mphf = NULL;
if (iters > g_numbers_len) {
if (iters > (int)g_numbers_len) {
fprintf(stderr, "No input with proper size.");
exit(-1);
}

View File

@ -526,7 +526,7 @@ void bmz_load(FILE *f, cmph_t *mphf)
cmph_uint32 bmz_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
bmz_data_t *bmz = mphf->data;
bmz_data_t *bmz = (bmz_data_t *)mphf->data;
cmph_uint32 h1 = hash(bmz->hashes[0], key, keylen) % bmz->n;
cmph_uint32 h2 = hash(bmz->hashes[1], key, keylen) % bmz->n;
DEBUGP("key: %.*s h1: %u h2: %u\n", keylen, key, h1, h2);
@ -554,7 +554,7 @@ void bmz_pack(cmph_t *mphf, void *packed_mphf)
{
bmz_data_t *data = (bmz_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing h1 type
CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
@ -606,12 +606,12 @@ cmph_uint32 bmz_packed_size(cmph_t *mphf)
*/
cmph_uint32 bmz_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint8 *h1_ptr = packed_mphf;
register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr);
register cmph_uint8 *h1_ptr = (cmph_uint8 *)packed_mphf;
register CMPH_HASH h1_type = (CMPH_HASH)(*((cmph_uint32 *)h1_ptr));
h1_ptr += 4;
register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr);
register CMPH_HASH h2_type = (CMPH_HASH)(*((cmph_uint32 *)h2_ptr));
h2_ptr += 4;
register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));

View File

@ -534,7 +534,7 @@ void bmz8_load(FILE *f, cmph_t *mphf)
cmph_uint8 bmz8_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
bmz8_data_t *bmz8 = mphf->data;
bmz8_data_t *bmz8 = (bmz8_data_t *)mphf->data;
cmph_uint8 h1 = (cmph_uint8)(hash(bmz8->hashes[0], key, keylen) % bmz8->n);
cmph_uint8 h2 = (cmph_uint8)(hash(bmz8->hashes[1], key, keylen) % bmz8->n);
DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2);
@ -561,7 +561,7 @@ void bmz8_destroy(cmph_t *mphf)
void bmz8_pack(cmph_t *mphf, void *packed_mphf)
{
bmz8_data_t *data = (bmz8_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing h1 type
CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
@ -612,12 +612,12 @@ cmph_uint32 bmz8_packed_size(cmph_t *mphf)
*/
cmph_uint8 bmz8_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint8 *h1_ptr = packed_mphf;
register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr);
register cmph_uint8 *h1_ptr = (cmph_uint8 *)packed_mphf;
register CMPH_HASH h1_type = (CMPH_HASH)(*((cmph_uint32 *)h1_ptr));
h1_ptr += 4;
register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr);
register CMPH_HASH h2_type = (CMPH_HASH)(*((cmph_uint32 *)h2_ptr));
h2_ptr += 4;
register cmph_uint8 *g_ptr = h2_ptr + hash_state_packed_size(h2_type);

View File

@ -685,7 +685,7 @@ static cmph_uint32 brz_fch_search(brz_data_t *brz, const char *key, cmph_uint32
cmph_uint32 brz_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
brz_data_t *brz = mphf->data;
brz_data_t *brz = (brz_data_t *)mphf->data;
cmph_uint32 fingerprint[3];
switch(brz->algo)
{
@ -728,7 +728,7 @@ void brz_destroy(cmph_t *mphf)
void brz_pack(cmph_t *mphf, void *packed_mphf)
{
brz_data_t *data = (brz_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
cmph_uint32 i,n;
// packing internal algo type
@ -858,7 +858,7 @@ cmph_uint32 brz_packed_size(cmph_t *mphf)
static cmph_uint32 brz_bmz8_search_packed(cmph_uint32 *packed_mphf, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint)
{
register CMPH_HASH h0_type = *packed_mphf++;
register CMPH_HASH h0_type = (CMPH_HASH)*packed_mphf++;
register cmph_uint32 *h0_ptr = packed_mphf;
packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type));
@ -867,9 +867,9 @@ static cmph_uint32 brz_bmz8_search_packed(cmph_uint32 *packed_mphf, const char *
register double c = (double)(*((cmph_uint64*)packed_mphf));
packed_mphf += 2;
register CMPH_HASH h1_type = *packed_mphf++;
register CMPH_HASH h1_type = (CMPH_HASH)*packed_mphf++;
register CMPH_HASH h2_type = *packed_mphf++;
register CMPH_HASH h2_type = (CMPH_HASH)*packed_mphf++;
register cmph_uint8 * size = (cmph_uint8 *) packed_mphf;
packed_mphf = (cmph_uint32 *)(size + k);
@ -911,7 +911,7 @@ static cmph_uint32 brz_bmz8_search_packed(cmph_uint32 *packed_mphf, const char *
static cmph_uint32 brz_fch_search_packed(cmph_uint32 *packed_mphf, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint)
{
register CMPH_HASH h0_type = *packed_mphf++;
register CMPH_HASH h0_type = (CMPH_HASH)*packed_mphf++;
register cmph_uint32 *h0_ptr = packed_mphf;
packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type));
@ -921,9 +921,9 @@ static cmph_uint32 brz_fch_search_packed(cmph_uint32 *packed_mphf, const char *k
register double c = (double)(*((cmph_uint64*)packed_mphf));
packed_mphf += 2;
register CMPH_HASH h1_type = *packed_mphf++;
register CMPH_HASH h1_type = (CMPH_HASH)*packed_mphf++;
register CMPH_HASH h2_type = *packed_mphf++;
register CMPH_HASH h2_type = (CMPH_HASH)*packed_mphf++;
register cmph_uint8 * size = (cmph_uint8 *) packed_mphf;
packed_mphf = (cmph_uint32 *)(size + k);
@ -972,7 +972,7 @@ static cmph_uint32 brz_fch_search_packed(cmph_uint32 *packed_mphf, const char *k
cmph_uint32 brz_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint32 *ptr = (cmph_uint32 *)packed_mphf;
register CMPH_ALGO algo = *ptr++;
register CMPH_ALGO algo = (CMPH_ALGO)*ptr++;
cmph_uint32 fingerprint[3];
switch(algo)
{

View File

@ -105,7 +105,7 @@ cmph_t *chd_new(cmph_config_t *mph, double c)
DEBUGP("packed_chd_phf_size = %u\n", packed_chd_phf_size);
/* Make sure that we have enough space to pack the mphf. */
packed_chd_phf = calloc((size_t)packed_chd_phf_size,(size_t)1);
packed_chd_phf = (cmph_uint8 *)calloc((size_t)packed_chd_phf_size,(size_t)1);
/* Pack the mphf. */
cmph_pack(chd_phf, packed_chd_phf);
@ -229,14 +229,14 @@ static inline cmph_uint32 _chd_search(void * packed_chd_phf, void * packed_cr, c
cmph_uint32 chd_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
register chd_data_t * chd = mphf->data;
register chd_data_t * chd = (chd_data_t *)mphf->data;
return _chd_search(chd->packed_chd_phf, chd->packed_cr, key, keylen);
}
void chd_pack(cmph_t *mphf, void *packed_mphf)
{
chd_data_t *data = (chd_data_t *)mphf->data;
cmph_uint32 * ptr = packed_mphf;
cmph_uint32 * ptr = (cmph_uint32 *)packed_mphf;
cmph_uint8 * ptr8;
// packing packed_cr_size and packed_cr
@ -263,7 +263,7 @@ cmph_uint32 chd_packed_size(cmph_t *mphf)
cmph_uint32 chd_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint32 * ptr = packed_mphf;
register cmph_uint32 * ptr = (cmph_uint32 *)packed_mphf;
register cmph_uint32 packed_cr_size = *ptr++;
register cmph_uint8 * packed_chd_phf = ((cmph_uint8 *) ptr) + packed_cr_size + sizeof(cmph_uint32);
return _chd_search(packed_chd_phf, ptr, key, keylen);

View File

@ -221,7 +221,7 @@ cmph_uint8 chd_ph_mapping(cmph_config_t *mph, chd_ph_bucket_t * buckets, chd_ph_
char * key = NULL;
cmph_uint32 keylen = 0;
chd_ph_map_item_t * map_item;
chd_ph_map_item_t * map_items = malloc(chd_ph->m*sizeof(chd_ph_map_item_t));
chd_ph_map_item_t * map_items = (chd_ph_map_item_t *)malloc(chd_ph->m*sizeof(chd_ph_map_item_t));
register cmph_uint32 mapping_iterations = 1000;
*max_bucket_size = 0;
while(1)
@ -317,7 +317,7 @@ chd_ph_sorted_list_t * chd_ph_ordering(chd_ph_bucket_t ** _buckets, chd_ph_item_
};
sorted_lists[i-1].size = 0;
// Store the buckets in a new array which is sorted by bucket sizes
output_buckets = calloc(nbuckets, sizeof(chd_ph_bucket_t)); // everything is initialized with zero
output_buckets = (chd_ph_bucket_t *)calloc(nbuckets, sizeof(chd_ph_bucket_t)); // everything is initialized with zero
// non_empty_buckets = nbuckets;
for(i = 0; i < nbuckets; i++)
@ -901,7 +901,7 @@ void chd_ph_destroy(cmph_t *mphf)
cmph_uint32 chd_ph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
register chd_ph_data_t * chd_ph = mphf->data;
register chd_ph_data_t * chd_ph = (chd_ph_data_t *)mphf->data;
cmph_uint32 hl[3];
register cmph_uint32 disp,position;
register cmph_uint32 probe0_num,probe1_num;
@ -921,7 +921,7 @@ cmph_uint32 chd_ph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
void chd_ph_pack(cmph_t *mphf, void *packed_mphf)
{
chd_ph_data_t *data = (chd_ph_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing hl type
CMPH_HASH hl_type = hash_get_type(data->hl);
@ -959,7 +959,7 @@ cmph_uint32 chd_ph_packed_size(cmph_t *mphf)
cmph_uint32 chd_ph_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register CMPH_HASH hl_type = *(cmph_uint32 *)packed_mphf;
register CMPH_HASH hl_type = (CMPH_HASH)*(cmph_uint32 *)packed_mphf;
register cmph_uint8 *hl_ptr = (cmph_uint8 *)(packed_mphf) + 4;
register cmph_uint32 * ptr = (cmph_uint32 *)(hl_ptr + hash_state_packed_size(hl_type));

View File

@ -276,7 +276,7 @@ void chm_load(FILE *f, cmph_t *mphf)
cmph_uint32 chm_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
chm_data_t *chm = mphf->data;
chm_data_t *chm = (chm_data_t *)mphf->data;
cmph_uint32 h1 = hash(chm->hashes[0], key, keylen) % chm->n;
cmph_uint32 h2 = hash(chm->hashes[1], key, keylen) % chm->n;
DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2);
@ -303,7 +303,7 @@ void chm_destroy(cmph_t *mphf)
void chm_pack(cmph_t *mphf, void *packed_mphf)
{
chm_data_t *data = (chm_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing h1 type
CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
@ -359,12 +359,12 @@ cmph_uint32 chm_packed_size(cmph_t *mphf)
*/
cmph_uint32 chm_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint8 *h1_ptr = packed_mphf;
register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr);
register cmph_uint8 *h1_ptr = (cmph_uint8 *)packed_mphf;
register CMPH_HASH h1_type = (CMPH_HASH)(*((cmph_uint32 *)h1_ptr));
h1_ptr += 4;
register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr);
register CMPH_HASH h2_type = (CMPH_HASH)(*((cmph_uint32 *)h2_ptr));
h2_ptr += 4;
register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));

View File

@ -70,7 +70,7 @@ void bm_register(const char* name, void (*func)(int), int iters) {
benchmark.func = func;
benchmark.iters = iters;
assert(!find_benchmark(name));
global_benchmarks = realloc(
global_benchmarks = (benchmark_t *)realloc(
global_benchmarks, (length + 2)*sizeof(benchmark_t));
global_benchmarks[length] = benchmark;
memset(&benchmark, 0, sizeof(benchmark_t)); // pivot

View File

@ -49,7 +49,7 @@ cmph_t *__cmph_load(FILE *f)
{
if (strcmp(algo_name, cmph_names[i]) == 0)
{
algo = i;
algo = (CMPH_ALGO)(i);
}
}
if (algo == CMPH_COUNT)

View File

@ -398,7 +398,7 @@ void fch_load(FILE *f, cmph_t *mphf)
cmph_uint32 fch_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
{
fch_data_t *fch = mphf->data;
fch_data_t *fch = (fch_data_t *)mphf->data;
cmph_uint32 h1 = hash(fch->h1, key, keylen) % fch->m;
cmph_uint32 h2 = hash(fch->h2, key, keylen) % fch->m;
h1 = mixh10h11h12 (fch->b, fch->p1, fch->p2, h1);
@ -423,7 +423,7 @@ void fch_destroy(cmph_t *mphf)
void fch_pack(cmph_t *mphf, void *packed_mphf)
{
fch_data_t *data = (fch_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;
// packing h1 type
CMPH_HASH h1_type = hash_get_type(data->h1);
@ -488,12 +488,12 @@ cmph_uint32 fch_packed_size(cmph_t *mphf)
*/
cmph_uint32 fch_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
register cmph_uint8 *h1_ptr = packed_mphf;
register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr);
register cmph_uint8 *h1_ptr = (cmph_uint8 *)packed_mphf;
register CMPH_HASH h1_type = (CMPH_HASH)*((cmph_uint32 *)h1_ptr);
h1_ptr += 4;
register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr);
register CMPH_HASH h2_type = (CMPH_HASH)*((cmph_uint32 *)h2_ptr);
h2_ptr += 4;
register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));

View File

@ -172,13 +172,13 @@ cmph_uint32 fch_buckets_get_nbuckets(fch_buckets_t * buckets)
cmph_uint32 * fch_buckets_get_indexes_sorted_by_size(fch_buckets_t * buckets)
{
cmph_uint32 i = 0;
cmph_int32 i = 0;
cmph_uint32 sum = 0, value;
cmph_uint32 *nbuckets_size = (cmph_uint32 *) calloc((size_t)buckets->max_size + 1, sizeof(cmph_uint32));
cmph_uint32 * sorted_indexes = (cmph_uint32 *) calloc((size_t)buckets->nbuckets, sizeof(cmph_uint32));
// collect how many buckets for each size.
for(i = 0; i < buckets->nbuckets; i++) nbuckets_size[fch_bucket_size(buckets->values + i)] ++;
for(i = 0; i < (int)buckets->nbuckets; i++) nbuckets_size[fch_bucket_size(buckets->values + i)] ++;
// calculating offset considering a decreasing order of buckets size.
value = nbuckets_size[buckets->max_size];
@ -190,7 +190,7 @@ cmph_uint32 * fch_buckets_get_indexes_sorted_by_size(fch_buckets_t * buckets)
nbuckets_size[i] = sum;
}
for(i = 0; i < buckets->nbuckets; i++)
for(i = 0; i < (int)buckets->nbuckets; i++)
{
sorted_indexes[nbuckets_size[fch_bucket_size(buckets->values + i)]] = (cmph_uint32)i;
nbuckets_size[fch_bucket_size(buckets->values + i)] ++;

View File

@ -101,7 +101,7 @@ hash_state_t *hash_state_load(const char *buf, cmph_uint32 buflen)
{
if (strcmp(buf, cmph_hash_names[i]) == 0)
{
hashfunc = i;
hashfunc = (CMPH_HASH)(i);
break;
}
}

View File

@ -177,7 +177,7 @@ int main(int argc, char **argv)
{
if (strcmp(cmph_names[i], optarg) == 0)
{
mph_algo = i;
mph_algo = (CMPH_ALGO)i;
valid = 1;
break;
}
@ -197,7 +197,7 @@ int main(int argc, char **argv)
if (strcmp(cmph_hash_names[i], optarg) == 0)
{
hashes = (CMPH_HASH *)realloc(hashes, sizeof(CMPH_HASH) * ( nhashes + 2 ));
hashes[nhashes] = i;
hashes[nhashes] = (CMPH_HASH)i;
hashes[nhashes + 1] = CMPH_HASH_COUNT;
++nhashes;
valid = 1;

View File

@ -147,7 +147,7 @@ int main(int argc, char **argv)
fprintf(stderr, "packed_size = %u\n", packed_size);
/* Make sure that we have enough space to pack the mphf. */
cmph_uint8 * packed_mphf = calloc((size_t)packed_size,(size_t)1);
cmph_uint8 * packed_mphf = (cmph_uint8 *)calloc((size_t)packed_size,(size_t)1);
/* Pack the mphf. */
cmph_pack(mphf, packed_mphf);