Skip to content
Open

Fix #75

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
22 changes: 13 additions & 9 deletions include/hash.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#if !defined(HASH)
#define HASH

#include <string>
#include <cstdint>

#include <modulo.hpp>
#include <trees.hpp>

#include <string>
#include <cstdint>

namespace nm {
template <std::int64_t M, std::int64_t P>
class Hash : public Arithmetic<std::int64_t> {
private:
std::size_t n;
vector<std::int64_t> hash;
vector<std::int64_t> power;
std::vector<std::int64_t> hash;
std::vector<std::int64_t> power;

public:
Hash(std::string &s);
Expand All @@ -24,10 +24,14 @@ namespace nm {
} // string hash

namespace nm {
const int32_m P_ASCII = 257; // UTF-8

/*
* M is expected to be a modular data type (int32_m, int32_n, int32_p)
* P is any prime that is less than but near to prime used to initialize
* modular data type
* M is expected to be a modular data type
* (such as int32_m, int32_n, int32_p).
* P is any prime that is greater than but
* near the values encountered during hashing.
* P must be lower than the Modulus.
*/
template <typename M, M P>
class ModHash{
Expand All @@ -48,7 +52,7 @@ namespace nm {
template <typename T>
class CoordinateCompression {
private:
Splay<T, T, Node<T> > coordinates;
Splay<Node<T, T>, T, T> coordinates;
std::vector<T> elements;
public:
CoordinateCompression(std::vector<T> data);
Expand Down
13 changes: 11 additions & 2 deletions src/hash.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <hash.hpp>

#include <sort.hpp>

#include <cassert>

namespace nm {
template<std::int64_t M, std::int64_t P>
Hash<M, P>::Hash(std::string &s) : Arithmetic<std::int64_t>::Arithmetic(M) {
Expand Down Expand Up @@ -48,6 +49,14 @@ namespace nm {
}
} // hash function int32_m

namespace nm {
// TODO: fix int32_m.
// Find a way around reinstantiation.
// Rename type definition.

template class nm::ModHash<int32_m, P_ASCII>;
}

namespace nm {
template <typename T>
CoordinateCompression<T>::CoordinateCompression(std::vector<T> data) {
Expand All @@ -69,7 +78,7 @@ namespace nm {

template <typename T>
T CoordinateCompression<T>::element(std::size_t i) {
assert(i < this->elements.size())
assert(i < this->elements.size());
return this->element[i];
}
}
Expand Down