• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A SIMD optimized fixed-length string class along with an adaptive hash table for fast searching

Str

Str is a char array wrapper providing some frequently used operations in the most efficient way(supporting AVX512 SIMD optimization), including string comparisons and conversion to/from integers.

StrHash

StrHash is an adaptive open addressing hash table template taking Str as key and providing a find function in the most efficient way. It's adaptive in that it can extract features from the keys contained in the table and train its hashing parameters dynamically to distribute the keys for avoiding collision.

StrHash is actually a subclass of std::map, so user can use whatever funcitons it provides to modify the table, and then call doneModify to train the table and fastFind to find keys in the table. Note that doneModify is pretty slow so it's not efficient to modify the table frequently between fastFind. It's recommended that clear be called immediately after doneModify if only fastFind is needed afterwards, so some memory can be saved.

StrHash currently supports 7 hash functions and one of which can be selected using template parameter HashFunc:

  • 0: djb ver1(default)
  • 1: djb ver2
  • 2: sax
  • 3: fnv
  • 4: oat
  • 5: murmur
  • 6: int(for integer keys)

User can also add other hash functions himself.

StrHash is also suitable to have integers(such as uint32_t or uint64_t) as key for searching. Define StrHash<8, Value, NullV, 6> for uint64_t and StrHash<4, Value, NullV, 6> for uint32_t, see benchfindint.cc for detailed usage.

Benchmark

Tests show that StrHash is 7x faster than std::unordered_map and 3x faster than other open addressing hash table implementations such as tsl::hopscotch_map, tsl::robin_map, robin_hood::unordered_map and google::dense_hash_map.

Str's operator== and compare is 2x faster than strncmp/memcmp or those of std::string.

Str's fromi and toi is 10x faster than stoi/strtol/to_string/sprintf.

benchfindstr.cc tests the performance of multiple string search solutions using the same data set. The data set contains the KRX option issue codes of Feb 2019 that we are interested in and are to be inserted into the table, and the first 1000 option issue codes we received from the market data(which are mostly of Feb 2019 but some are of other months) and are to be searched in the table. In benchfindstr.cc:

  • bench_hash<0~5> compair the performance of different hash functions StrHash supports.
  • bench_hash vs other searching solutions shows how StrHash is faster than others.
  • bench_map vs bench_string_map and bench_bsearch vs bench_string_bsearch show how Str is faster than std::string.

benchfindint.cc tests the performance of multiple integer search solutions in similar way to benchfindstr.cc. The data set contains the SHFE instrument No of type uint64_t. Here bench_hash6 should be the most suitable method.

benchcmp.cc tests string comparison operations.

benchnum.cc tests conversions to/from integers.

More Repositories

1

fmtlog

fmtlog is a performant fmtlib-style logging library with latency in nanoseconds.
C++
768
star
2

tcpshm

A connection-oriented persistent message queue framework based on TCP or SHM(shared memory)
C++
454
star
3

tscns

A low overhead nanosecond clock based on x86 TSC
C++
286
star
4

SPSC_Queue

A highly optimized single producer single consumer message queue C++ template
C++
242
star
5

pollnet

A collection of non-blocking(polling) network libs for Linux, also support solarflare APIs(Tcpdirect/Efvi)
C++
208
star
6

websocket

A single header c++ websocket client/server lib for linux
C++
165
star
7

WFMPMC

A bounded wait-free(almost) zero-copy MPMC queue written in C++11, which can also reside in SHM for IPC
C++
109
star
8

TCP-UDP-Proxy

A proxy server program written in C++ that can forward TCP or UDP packets
C++
87
star
9

SPMC_Queue

A simple and efficient single producer multiple consumer queue, suititable for both ITC and IPC.
C++
76
star
10

MPSC_Queue

A multi-producer single consumer queue C++ template suitable for async logging with SHM IPC support
C++
73
star
11

PubSubQueue

An efficient single publisher multiple subscriber message queue for Linux IPC
C++
54
star
12

admincmd

A shell style command line framework which can easily be incorporated into a linux c++ server, supporting telnet/nc clients
C++
38
star
13

NanoLogLite

A revised version of NanoLog which writes human readable log file, and is easier to use.
C++
36
star
14

efvitcp

A Tcp/Ip stack implementation on top of Solarflare ef_vi, and a C++ headers only framework for tcp multiplexing client/server.
30
star
15

Algos

A collection of C++ libraries I personally maintained and used in competitive programming problems.
C++
4
star
16

SuperImageView-for-Android

A powerful Image browser for Android that supports multiple gestures
Java
1
star