Skip to content

Commit 789da64

Browse files
committed
minor
1 parent 41d9c78 commit 789da64

12 files changed

Lines changed: 60 additions & 55 deletions

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
build/
2-
old/
32
.DS_Store
4-
cmake-build*
5-
.idea

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ project(PTHASH)
44
if (NOT CMAKE_BUILD_TYPE)
55
set(CMAKE_BUILD_TYPE "Release")
66
endif ()
7-
MESSAGE(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
7+
8+
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
89

910
if (NOT TARGET PTHASH)
1011
add_library(PTHASH INTERFACE)
@@ -15,6 +16,7 @@ if (NOT TARGET PTHASH)
1516
target_compile_features(PTHASH INTERFACE cxx_std_17)
1617

1718
MESSAGE(STATUS "Compiling for processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
19+
1820
if (UNIX AND (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64"))
1921
MESSAGE(STATUS "Compiling with flags: -march=native -mbmi2 -msse4.2")
2022
target_compile_options(PTHASH INTERFACE -march=native)
@@ -44,6 +46,7 @@ if (NOT TARGET PTHASH)
4446
target_compile_options(PTHASH INTERFACE -fsanitize=address -fno-omit-frame-pointer)
4547
endif()
4648

49+
MESSAGE(STATUS "Configuring the `bits` library:")
4750
add_subdirectory(external/bits)
4851
target_link_libraries(PTHASH INTERFACE BITS)
4952
endif()

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright 2020-2024 Giulio Ermanno Pibiri, Roberto Trani, Stefan Hermann, Hans-Peter Lehmann, Peter Sanders, Stefan Walzer
3+
Copyright 2020-2025 Giulio Ermanno Pibiri, Roberto Trani, Stefan Hermann, Hans-Peter Lehmann, Peter Sanders, Stefan Walzer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
- [*Parallel and External-Memory Construction of Minimal Perfect Hash Functions with PTHash*](https://ieeexplore.ieee.org/document/10210677) (TKDE 2023),
1313
- [*PHOBIC: Perfect Hashing with Optimized Bucket Sizes and Interleaved Coding*](https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ESA.2024.69) (ESA 2024).
1414

15-
**Please, cite these papers if you use PTHash or PHOBIC.**
15+
**Please, cite these papers if you use PTHash.**
16+
17+
**Rust**: if you use the Rust programming language, we recommend the [PtrHash](https://github.com/RagnarGrootKoerkamp/PtrHash) library.
1618

1719
### Development note
1820

1921
The description of PTHash in the SIGIR and TKDE papers uses the `c` parameter
20-
to control the number of buckets used during the search.
22+
to control the number of buckets for the search phase of the algorithm.
2123
You can get a version of the library using the `c` parameter [here](https://github.com/jermp/pthash/releases/tag/v2.0.0) (Release v2).
2224
The current library
2325
uses instead a parameter called "lambda", as described in the ESA paper.
@@ -58,7 +60,7 @@ Integrating PTHash in your own project is very simple.
5860
If you use `git`, the easiest way to add PTHash is via `git add submodule` as follows.
5961

6062
git submodule add https://github.com/jermp/pthash.git
61-
git submodule update --recursive --init
63+
git submodule update --recursive --init
6264

6365
Then include the following in your `CMakeLists.txt`, which takes care of
6466
setting up the include paths and compiler flags of PTHash and its dependencies:
@@ -69,7 +71,7 @@ setting up the include paths and compiler flags of PTHash and its dependencies:
6971
To construct a perfect hash function, include `pthash.hpp` and create an instance of `pthash::single_phf<...>` (PTHash),
7072
`pthash::partitioned_phf<...>` (PTHash-HEM), or `pthash::dense_partitioned_phf<...>` (PHOBIC).
7173
For convenience, we also give `pthash::phobic<...>` which includes the configuration options for
72-
optimized bucket assignment function (OB) and interleaved coding (IC). Refer to `src/example.cpp` for an example.
74+
optimized bucket assignment function and interleaved coding. Refer to `src/example.cpp` for an example.
7375

7476
Compiling the Benchmark and Example Code
7577
-----
@@ -100,7 +102,7 @@ For a testing environment, use the following instead:
100102
cmake .. -D CMAKE_BUILD_TYPE=Debug -D PTHASH_USE_SANITIZERS=On
101103
make
102104

103-
(NOTE: Beware that the software will result in a much slower execution when running in debug mode and using sanitizers. Use this only for debug purposes, not to run performance tests.)
105+
**NOTE**: Beware that the software will result in a much slower execution when running in debug mode and using sanitizers. Use this only for debug purposes, not to run performance tests.)
104106

105107
### Enable Large Bucket-Id Type
106108

@@ -116,7 +118,7 @@ Quick Start
116118

117119
For a quick start, see the source file `src/example.cpp`.
118120
The example shows how to setup a simple build configuration
119-
for PTHash (parameters, base hasher, search type, and encoder).
121+
for PTHash (parameters, base hasher, bucketer, and encoder types).
120122

121123
After compilation, run this example with
122124

@@ -138,28 +140,29 @@ shows the usage of the driver program. In the following, we illustrate some exam
138140

139141
The command
140142

141-
./build -n 10000000 -l 4.3 -a 0.99 -r xor -e D-D -b skew -q 3000000 -s 0 -p 2000000 -t 8 --verbose --minimal --check
143+
./build -n 10000000 -l 4.3 -a 0.99 -e D-D -b skew -q 3000000 -s 0 -p 2000000 -t 8 --verbose --minimal --check
142144

143-
builds a MPHF over 10M random 64-bit integers, using
145+
builds a minimal (option `--minimal`) PHF over 10M random 64-bit integers, using
144146

145-
- avg. bucket size of 4.3 (`-l = 4.3`);
147+
- avg. bucket size, "lambda", of 4.3 (`-l = 4.3`);
146148
- load factor of 0.99 (`-a 0.99`);
147-
- xor-type search (`-r xor`);
148149
- the encoder `D-D` to compress the data structure;
149150
- the `skew` bucketer type (`-b skew`);
150151
- seed 0 (`-s 0`);
151-
- avg. partition size 2,000,000 (`-p 2000000`);
152+
- avg. partition size 2M (`-p 2000000`);
152153
- 8 parallel threads (`-t 8`).
153154

154-
Also, it performs 3M queries (`-q 3000000`) to benchmark the speed of lookup queries and check the correctness of the function.
155+
Also, it performs 3M queries (`-q 3000000`) to benchmark the speed of lookup queries and check the correctness of the function (option `--check`).
155156

156157
### Example 2
157158

158159
For the following example,
159160
we are going to use the strings from the UK-2005 URLs collection,
160161
which can be downloaded by clicking
161-
[here](http://data.law.di.unimi.it/webdata/uk-2005/uk-2005.urls.gz).
162-
(This is also one of the datasets used in the paper.)
162+
[here](http://data.law.di.unimi.it/webdata/uk-2005/uk-2005.urls.gz)
163+
or typing
164+
165+
wget http://data.law.di.unimi.it/webdata/uk-2005/uk-2005.urls.gz
163166

164167
The file is ~300 MB compressed using gzip (2.86 GB uncompressed).
165168

@@ -174,15 +177,13 @@ The file contains one string per line, for a total of 39,459,925 strings.
174177

175178
The command
176179

177-
./build -n 39459925 -i ~/Downloads/uk-2005.urls -l 3.5 -a 0.94 -e inter-R -r add -b skew -s 0 -q 3000000 -p 2500 -t 8 --dense --minimal --verbose --check
180+
./build -n 39459925 -i uk-2005.urls -l 3.5 -e R-int -b skew -s 0 -q 3000000 -t 8 --dense --minimal --verbose --check
178181

179182
builds a MPHF using the strings of the file as input keys, where
180183

181-
- the function is of type *dense partitioned"* because option `--dense` is specified, with an avg. partition size of 2500 (`-p 2500`);
184+
- the function is of type *dense partitioned"* because option `--dense` is specified;
182185
- the avg. number of buckets is set to 3.5 (`-l 3.5`);
183-
- the load factor is set to 0.94 (`-a 0.94`);
184-
- the data structure is compressed using interleaved Rice codes (`-e inter-R`);
185-
- the search algorithm is additive displacement (`-r add`);
186+
- the data structure is compressed using interleaved Rice codes (`-e R-int`);
186187
- the type of bucketer used is `skew`;
187188
- the seed used for the construction is 0 (`-s 0`);
188189
- the number of threads used for the construction are 8 (`-t 8`);
@@ -192,9 +193,10 @@ builds a MPHF using the strings of the file as input keys, where
192193

193194
The command
194195

195-
./build -n 39459925 -i ~/Downloads/uk-2005.urls -l 3.5 -a 0.94 -e PC -r add -b skew -s 0 -q 3000000 -p 2500000 -t 8 -m 1 --minimal --verbose --check --external
196+
./build -n 39459925 -i uk-2005.urls -l 3.5 -a 0.94 -e PC -b skew -s 0 -q 3000000 -p 2500000 -t 8 -m 1 --minimal --verbose --check --external
196197

197-
builds a MPHF using most of the parameters used in Example 2 but the function is built in external memory (option `--external`) using 1 GB of RAM (option `-m 1`), and with avg. partition size of 2.5M and compressing the data structure with a partitioned compact encoding (`-e PC`).
198+
builds a MPHF using most of the parameters used in Example 2 but the function is built in external memory (option `--external`) using 1 GB of RAM (option `-m 1`), with avg. partition size of 2.5M,
199+
and compressing the data structure with a partitioned compact encoding (`-e PC`).
198200

199201
Reading Keys from Standard Input
200202
-----
@@ -205,14 +207,14 @@ in combination with option `-i -`. This is very useful when building keys from c
205207
Some examples below.
206208

207209
for i in $(seq 1 1000000) ; do echo $i ; done > foo.txt
208-
cat foo.txt | ./build --minimal -l 3.4 -a 0.94 -e R-R -r add -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
210+
cat foo.txt | ./build --minimal -l 3.4 -a 0.94 -e R-R -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
209211

210212
gzip foo.txt
211-
zcat foo.txt.gz | ./build --minimal -l 3.4 -a 0.94 -e R-R -r add -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
213+
zcat foo.txt.gz | ./build --minimal -l 3.4 -a 0.94 -e R-R -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
212214

213215
gunzip foo.txt.gz
214216
zstd foo.txt
215-
zstdcat foo.txt.zst | ./build --minimal -l 3.4 -a 0.94 -e R-R -r add -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
217+
zstdcat foo.txt.zst | ./build --minimal -l 3.4 -a 0.94 -e R-R -b skew -n 1000000 -q 0 -m 1 -i - -o foo.mph --verbose --external
216218

217219
**Note**: you may need to write `zcat < foo.txt.gz | (...)` on Mac OSX.
218220

include/builders/internal_memory_builder_partitioned_phf.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ struct internal_memory_builder_partitioned_phf {
6363
}
6464

6565
if (config.dense_partitioning) {
66-
if (config.alpha < 1.0 and config.verbose) {
67-
std::cout << "alpha defaulting to 1.0 for --dense" << std::endl;
68-
}
66+
// if (config.verbose) std::cout << "alpha value ignored for --dense" << std::endl;
6967
m_table_size = constants::table_size_per_partition * num_partitions;
7068
} else {
7169
uint64_t cumulative_size = 0;
@@ -88,19 +86,29 @@ struct internal_memory_builder_partitioned_phf {
8886
partition_config.num_buckets = m_num_buckets_per_partition;
8987
if (config.dense_partitioning) {
9088
partition_config.table_size = constants::table_size_per_partition;
89+
partition_config.alpha = 1.0;
9190
}
9291
if (config.verbose) {
9392
if (config.dense_partitioning) {
9493
std::cout << "table_size_per_partition = " << partition_config.table_size
9594
<< std::endl;
9695
}
9796
uint64_t largest_partition_size = 0;
97+
uint64_t smallest_partition_size = uint64_t(-1);
9898
for (auto const& partition : partitions) {
9999
if (partition.size() > largest_partition_size) {
100100
largest_partition_size = partition.size();
101101
}
102+
if (partition.size() < smallest_partition_size) {
103+
smallest_partition_size = partition.size();
104+
}
102105
}
103-
std::cout << "(largest_partition_size = " << largest_partition_size << ")" << std::endl;
106+
std::cout << "smallest_partition_size = " << smallest_partition_size << std::endl;
107+
std::cout << "largest_partition_size = " << largest_partition_size << std::endl;
108+
std::cout << "load factor of partitions: "
109+
<< (smallest_partition_size * 1.0) / partition_config.table_size
110+
<< " <= alpha <= "
111+
<< (largest_partition_size * 1.0) / partition_config.table_size << std::endl;
104112
std::cout << "num_buckets_per_partition = " << partition_config.num_buckets
105113
<< std::endl;
106114
}

include/builders/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct build_timings {
3939
struct build_configuration {
4040
build_configuration()
4141
: lambda(4.5)
42-
, alpha(1.0)
42+
, alpha(constants::default_alpha)
4343
, avg_partition_size(0)
4444
, num_buckets(constants::invalid_num_buckets)
4545
, table_size(constants::invalid_table_size)

include/dense_partitioned_phf.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
namespace pthash {
66

7-
template <typename Hasher, //
8-
typename Bucketer, //
9-
typename Encoder, //
10-
bool Minimal>
7+
template <typename Hasher, typename Bucketer, typename Encoder, bool Minimal>
118
struct dense_partitioned_phf //
129
{
1310
static_assert(

include/partitioned_phf.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
namespace pthash {
1010

11-
template <typename Hasher, //
12-
typename Bucketer, //
13-
typename Encoder, //
14-
bool Minimal>
11+
template <typename Hasher, typename Bucketer, typename Encoder, bool Minimal>
1512
struct partitioned_phf //
1613
{
1714
static_assert(

include/single_phf.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
namespace pthash {
99

10-
template <typename Hasher, //
11-
typename Bucketer, //
12-
typename Encoder, //
13-
bool Minimal>
10+
template <typename Hasher, typename Bucketer, typename Encoder, bool Minimal>
1411
struct single_phf //
1512
{
1613
static_assert(

include/utils/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const uint64_t available_ram = sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_P
2020
static const uint64_t invalid_seed = uint64_t(-1);
2121
static const uint64_t invalid_num_buckets = uint64_t(-1);
2222
static const uint64_t invalid_table_size = uint64_t(-1);
23+
static const double default_alpha = 0.94;
2324

2425
/* for partitioned_phf */
2526
static const uint64_t min_partition_size = 100000;

0 commit comments

Comments
 (0)