Skip to content

Commit 6bfbadb

Browse files
committed
Wrap cityhash in namespace and add accessor methods for metagraph compatibility
Changes for metagraph integration: 1. Wrap cityhash in namespace to avoid typedef pollution - cityhash.hpp and cityhash.cpp: Wrapped in 'cityhash' namespace - Prevents conflicts with rollinghashcpp uint64 typedef - hash_util.hpp: Use cityhash::CityHash128WithSeed instead of static CityMurmur 2. Add public accessor methods to dictionary - Added kmer_type typedef for easier template parameter extraction - Added strings() accessor returning m_spss.strings bit vector - Added strings_offsets() accessor returning m_spss.strings_offsets - Moved strings_offsets() next to string_offsets() for better organization 3. Build system changes - CMakeLists.txt: Added cityhash.cpp to SSHASH_SOURCES for linking 4. Update pthash submodule - Points to fix for compute_empirical_entropy multiple definition error
1 parent 2dbcdd0 commit 6bfbadb

6 files changed

Lines changed: 24 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ set(Z_LIB_SOURCES
6060
external/gz/zip_stream.cpp
6161
)
6262

63+
set(CITYHASH_SOURCES
64+
external/cityhash/cityhash.cpp
65+
)
66+
6367
set(SSHASH_SOURCES
6468
src/build.cpp
6569
src/dictionary.cpp
@@ -81,6 +85,7 @@ set(SSHASH_INCLUDE_DIRS
8185
# Create a static lib
8286
add_library(sshash_static STATIC
8387
${Z_LIB_SOURCES}
88+
${CITYHASH_SOURCES}
8489
${SSHASH_SOURCES}
8590
)
8691

external/cityhash/cityhash.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <algorithm>
3535
#include <string.h> // for memcpy and memset
3636

37+
namespace cityhash {
38+
3739
using namespace std;
3840

3941
static uint64 UNALIGNED_LOAD64(const char* p) {
@@ -442,4 +444,6 @@ uint128 CityHashCrc128(const char* s, size_t len) {
442444
}
443445
}
444446

445-
#endif
447+
#endif
448+
449+
} // namespace cityhash

external/cityhash/cityhash.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include <stdlib.h> // for size_t.
4949
#include <utility>
5050

51+
namespace cityhash {
52+
5153
// Microsoft Visual Studio may not have stdint.h.
5254
#if defined(_MSC_VER) && (_MSC_VER < 1600)
5355
typedef unsigned char uint8_t;
@@ -112,4 +114,6 @@ void CityHashCrc256(const char* s, size_t len, uint64* result);
112114

113115
#endif // __SSE4_2__
114116

117+
} // namespace cityhash
118+
115119
#endif // CITY_HASH_H_

external/pthash

include/dictionary.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct dictionary //
6868
/* Return the string of the kmer whose id is kmer_id. */
6969
void access(uint64_t kmer_id, char* string_kmer) const;
7070

71+
/* Accessor for internal bit vector */
72+
bits::bit_vector const& strings() const { return m_spss.strings; }
73+
7174
/* Membership queries. */
7275
bool is_member(char const* string_kmer, bool check_reverse_complement = true) const;
7376
bool is_member(Kmer uint_kmer, bool check_reverse_complement = true) const;
@@ -104,6 +107,9 @@ struct dictionary //
104107
return m_spss.string_offsets(string_id);
105108
}
106109

110+
/* Accessor for internal offsets structure */
111+
Offsets const& strings_offsets() const { return m_spss.strings_offsets; }
112+
107113
iterator at_string_id(const uint64_t string_id) const {
108114
assert(string_id < num_strings());
109115
auto [begin, end] = string_offsets(string_id);

include/hash_util.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "external/pthash/include/pthash.hpp"
4-
#include "external/cityhash/cityhash.cpp"
4+
#include "external/cityhash/cityhash.hpp"
55
#include "constants.hpp"
66

77
namespace sshash {
@@ -10,7 +10,7 @@ struct minimizers_city_hasher_128 {
1010
typedef pthash::hash128 hash_type;
1111

1212
static inline pthash::hash128 hash(uint64_t const minimizer, uint64_t seed) {
13-
auto ret = CityMurmur(reinterpret_cast<char const*>(&minimizer), //
13+
auto ret = cityhash::CityHash128WithSeed(reinterpret_cast<char const*>(&minimizer), //
1414
sizeof(minimizer), {seed, ~seed});
1515
return {ret.first, ret.second};
1616
}
@@ -60,7 +60,7 @@ struct kmers_city_hasher_128 {
6060
typedef pthash::hash128 hash_type;
6161

6262
static inline pthash::hash128 hash(Kmer const x, uint64_t seed) {
63-
auto ret = CityMurmur(reinterpret_cast<char const*>(&(x.bits)), //
63+
auto ret = cityhash::CityHash128WithSeed(reinterpret_cast<char const*>(&(x.bits)), //
6464
sizeof(x.bits), {seed, ~seed});
6565
return {ret.first, ret.second};
6666
}

0 commit comments

Comments
 (0)