Skip to content

Commit

Permalink
bring interface template type decs in line with cppyy standards, add …
Browse files Browse the repository at this point in the history
…a mphf test file
  • Loading branch information
camillescott committed Apr 8, 2019
1 parent 0bbcf95 commit ec8404b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
23 changes: 11 additions & 12 deletions interface.hh
Expand Up @@ -2,24 +2,23 @@

#include <cstdint>

template class boomphf::SingleHashFunctor<uint16_t>;
template class boomphf::SingleHashFunctor<uint32_t>;
template class boomphf::SingleHashFunctor<unsigned short>;
template class boomphf::SingleHashFunctor<unsigned int>;
template class boomphf::SingleHashFunctor<uint64_t>;
template class boomphf::SingleHashFunctor<unsigned long long>;

template class boomphf::SingleHashFunctor<int16_t>;
template class boomphf::SingleHashFunctor<int32_t>;
template class boomphf::SingleHashFunctor<short>;
template class boomphf::SingleHashFunctor<int>;
template class boomphf::SingleHashFunctor<int64_t>;
template class boomphf::SingleHashFunctor<long long>;

template class boomphf::mphf<uint16_t, boomphf::SingleHashFunctor<uint16_t>>;
template class boomphf::mphf<uint32_t, boomphf::SingleHashFunctor<uint32_t>>;

template class boomphf::mphf<unsigned short, boomphf::SingleHashFunctor<unsigned short>>;
template class boomphf::mphf<unsigned int, boomphf::SingleHashFunctor<unsigned int>>;
template class boomphf::mphf<uint64_t, boomphf::SingleHashFunctor<uint64_t>>;
template class boomphf::mphf<unsigned long long, boomphf::SingleHashFunctor<unsigned long long>>;

template class boomphf::mphf<int16_t, boomphf::SingleHashFunctor<int16_t>>;
template class boomphf::mphf<int32_t, boomphf::SingleHashFunctor<int32_t>>;
template class boomphf::mphf<short, boomphf::SingleHashFunctor<short>>;
template class boomphf::mphf<int, boomphf::SingleHashFunctor<int>>;
template class boomphf::mphf<int64_t, boomphf::SingleHashFunctor<int64_t>>;

namespace boomphf {
typedef boomphf::mphf<int64_t, boomphf::SingleHashFunctor<int64_t>> DefaultMPHF;
}
template class boomphf::mphf<long long, boomphf::SingleHashFunctor<long long>>;
37 changes: 37 additions & 0 deletions py/tests/test_bbhash_basic.py
@@ -0,0 +1,37 @@
from cppyy.gbl import std
from cppyy_bbhash import boomphf

import pytest
import random

@pytest.fixture(params=['ULong64_t', 'int', 'unsigned int'])
def mphf_type(request):
return request.param, boomphf.mphf[request.param, boomphf.SingleHashFunctor[request.param]]


@pytest.mark.parametrize('sample_size', (10, 100, 1000))
def test_mphf_lookup(sample_size, mphf_type):
''' Test basic lookup
'''
elem_t, mphf_t = mphf_type

sample_space = list(range(10 * sample_size))
items = std.vector[elem_t](random.sample(sample_space, sample_size))
ph = mphf_t(len(items), items, 1, 2.0, False, False)

mapped = [ph.lookup(item) for item in items]
assert sorted(mapped) == list(range(sample_size))


@pytest.mark.parametrize('sample_size', (10, 100, 1000))
def test_mphf_query(sample_size, mphf_type):
''' Test the pythonized lookup, which is mapped to query
'''
elem_t, mphf_t = mphf_type

sample_space = list(range(10 * sample_size))
items = std.vector[elem_t](random.sample(sample_space, sample_size))
ph = mphf_t(len(items), items, 1, 2.0, False, False)

mapped = [ph.query(item) for item in items]
assert sorted(mapped) == list(range(sample_size))

0 comments on commit ec8404b

Please sign in to comment.