Fixed bug in ranking function.
This commit is contained in:
parent
9375a15dd4
commit
57ce26c5b1
@ -170,7 +170,9 @@ void MPHIndex::Ranking() {
|
||||
while (1) {
|
||||
if (i == ranktable_size_) break;
|
||||
uint32_t nbytes = size < nbytes_total ? size : nbytes_total;
|
||||
for (uint32_t j = 0; j < nbytes; ++j) count += kBdzLookupIndex[g_[offset + j]];
|
||||
for (uint32_t j = 0; j < nbytes; ++j) {
|
||||
count += kBdzLookupIndex[g_.data()[offset + j]];
|
||||
}
|
||||
ranktable[i] = count;
|
||||
offset += nbytes;
|
||||
nbytes_total -= size;
|
||||
|
@ -69,14 +69,14 @@ class mph_map {
|
||||
void erase(iterator pos);
|
||||
void erase(const key_type& k);
|
||||
pair<iterator, bool> insert(const value_type& x);
|
||||
iterator find(const key_type& k) { return slow_find(k, index_.perfect_hash(k)); }
|
||||
const_iterator find(const key_type& k) const { return slow_find(k, index_.perfect_hash(k)); };
|
||||
iterator find(const key_type& k) { return slow_find(k, index_.minimal_perfect_hash(k)); }
|
||||
const_iterator find(const key_type& k) const { return slow_find(k, index_.minimal_perfect_hash(k)); };
|
||||
typedef int32_t my_int32_t; // help macros
|
||||
int32_t index(const key_type& k) const;
|
||||
data_type& operator[](const key_type &k);
|
||||
const data_type& operator[](const key_type &k) const;
|
||||
|
||||
size_type bucket_count() const { return index_.perfect_hash_size() + slack_.bucket_count(); }
|
||||
size_type bucket_count() const { return index_.minimal_perfect_hash_size() + slack_.bucket_count(); }
|
||||
void rehash(size_type nbuckets /*ignored*/);
|
||||
|
||||
protected: // mimicking STL implementation
|
||||
@ -105,8 +105,8 @@ class mph_map {
|
||||
|
||||
// Experimental functions, not always faster
|
||||
iterator fast_find(const key_type& k);
|
||||
iterator slow_find(const key_type& k, uint32_t perfect_hash);
|
||||
const_iterator slow_find(const key_type& k, uint32_t perfect_hash) const;
|
||||
iterator slow_find(const key_type& k, uint32_t minimal_perfect_hash);
|
||||
const_iterator slow_find(const key_type& k, uint32_t minimal_perfect_hash) const;
|
||||
|
||||
void pack();
|
||||
std::vector<value_type> values_;
|
||||
@ -169,13 +169,13 @@ MPH_MAP_METHOD_DECL(void_type, pack)() {
|
||||
make_iterator_first(begin()),
|
||||
make_iterator_first(end()), size_);
|
||||
assert(success);
|
||||
std::vector<value_type> new_values(index_.perfect_hash_size());
|
||||
std::vector<value_type> new_values(index_.minimal_perfect_hash_size());
|
||||
new_values.reserve(new_values.size() * 2);
|
||||
std::vector<bool> new_present(index_.perfect_hash_size(), false);
|
||||
std::vector<bool> new_present(index_.minimal_perfect_hash_size(), false);
|
||||
new_present.reserve(new_present.size() * 2);
|
||||
for (iterator it = begin(), it_end = end(); it != it_end; ++it) {
|
||||
size_type id = index_.perfect_hash(it->first);
|
||||
assert(id < index_.perfect_hash_size());
|
||||
size_type id = index_.minimal_perfect_hash(it->first);
|
||||
assert(id < index_.minimal_perfect_hash_size());
|
||||
assert(id < new_values.size());
|
||||
new_values[id] = *it;
|
||||
new_present[id] = true;
|
||||
@ -212,10 +212,10 @@ MPH_MAP_METHOD_DECL(void_type, erase)(const key_type& k) {
|
||||
erase(it);
|
||||
}
|
||||
|
||||
MPH_MAP_METHOD_DECL(const_iterator, slow_find)(const key_type& k, uint32_t perfect_hash) const {
|
||||
if (__builtin_expect(index_.perfect_hash_size(), 1)) {
|
||||
if (__builtin_expect(present_[perfect_hash], true)) {
|
||||
auto vit = values_.begin() + perfect_hash;
|
||||
MPH_MAP_METHOD_DECL(const_iterator, slow_find)(const key_type& k, uint32_t minimal_perfect_hash) const {
|
||||
if (__builtin_expect(index_.minimal_perfect_hash_size(), 1)) {
|
||||
if (__builtin_expect(present_[minimal_perfect_hash], true)) {
|
||||
auto vit = values_.begin() + minimal_perfect_hash;
|
||||
if (equal_(k, vit->first)) return make_iterator(vit);
|
||||
}
|
||||
}
|
||||
@ -227,10 +227,10 @@ MPH_MAP_METHOD_DECL(const_iterator, slow_find)(const key_type& k, uint32_t perfe
|
||||
return end();
|
||||
}
|
||||
|
||||
MPH_MAP_METHOD_DECL(iterator, slow_find)(const key_type& k, uint32_t perfect_hash) {
|
||||
if (__builtin_expect(index_.perfect_hash_size(), 1)) {
|
||||
if (__builtin_expect(present_[perfect_hash], true)) {
|
||||
auto vit = values_.begin() + perfect_hash;
|
||||
MPH_MAP_METHOD_DECL(iterator, slow_find)(const key_type& k, uint32_t minimal_perfect_hash) {
|
||||
if (__builtin_expect(index_.minimal_perfect_hash_size(), 1)) {
|
||||
if (__builtin_expect(present_[minimal_perfect_hash], true)) {
|
||||
auto vit = values_.begin() + minimal_perfect_hash;
|
||||
if (equal_(k, vit->first)) return make_iterator(vit);
|
||||
}
|
||||
}
|
||||
@ -244,7 +244,7 @@ MPH_MAP_METHOD_DECL(iterator, slow_find)(const key_type& k, uint32_t perfect_has
|
||||
|
||||
MPH_MAP_METHOD_DECL(my_int32_t, index)(const key_type& k) const {
|
||||
if (index_.size() == 0) return -1;
|
||||
return index_.perfect_hash(k);
|
||||
return index_.minimal_perfect_hash(k);
|
||||
}
|
||||
|
||||
MPH_MAP_METHOD_DECL(data_type&, operator[])(const key_type& k) {
|
||||
|
Loading…
Reference in New Issue
Block a user