• Stars
    star
    130
  • Rank 267,562 (Top 6 %)
  • Language
    Erlang
  • License
    MIT License
  • Created about 13 years ago
  • Updated 6 months ago

Reviews

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

Repository Details

Erlang Trie Implementation

Erlang Trie Implementation

The data structure is only for storing keys as strings (lists of integers), but is able to get performance close to the process dictionary when doing key lookups (based on results here with the benchmark here). So, this data structure is (currently) the quickest for lookups on key-value pairs where all keys are strings, if you ignore the process dictionary (which many argue should never be used).

The implementation stores leaf nodes as the string suffix because it is a PATRICIA trie (PATRICIA - Practical Algorithm to Retrieve Information Coded in Alphanumeric, D.R.Morrison (1968)). Storing leaf nodes this way helps avoid single child leafs (compressing the tree a little bit).

The full OTP dict API is supported in addition to other functions. Functions like foldl, iter, itera, and foreach traverse in alphabetical order. Functions like map and foldr traverse in reverse alphabetical order. There are also functions like find_prefix, is_prefix, and is_prefixed that check if a prefix exists within the trie. The functions with a "_similar" suffix like find_similar, foldl_similar, and foldr_similar all operate with trie elements that share a common prefix with the supplied string.

The trie data structure supports string patterns. The functions find_match/2, fold_match/4, and pattern_parse/2 utilize patterns that contain a"*"wildcard character(s) (equivalent to ".+" regex while"**"is forbidden). The function find_match/2 operates on a trie filled with patterns when supplied a string non-pattern, while the function fold_match/4 operates on a trie without patterns when supplied a string pattern. The functions find_match2/2 and pattern2_parse/2 add "?" as an additional wildcard character (with "**", "??", "*?" and "?*" forbidden) that consumes greedily to the next character ("?" must not be the last character in the pattern).

The btrie data structure was added because many people wanted a quick associative data structure for binary keys. However, other alternatives provide better efficiency, so the btrie is best used for functions that can not be found elsewhere (or perhaps extra-long keys)... more testing would be needed to determine the best use-cases of the btrie.

Tests

rebar compile
ERL_LIBS="/path/to/proper" rebar eunit

Author

Michael Truog (mjtruog at protonmail dot com)

License

MIT License

More Repositories

1

uuid

Erlang Native UUID Generation
Erlang
213
star
2

pqueue

Erlang Priority Queues
Erlang
169
star
3

pest

🪲 Primitive Erlang Security Tool
Erlang
99
star
4

cpg

CloudI Process Groups
Erlang
92
star
5

GEPD

Generic Erlang Port [Driver]: Automatically generate an Erlang port driver or Erlang port for C/C++ bindings using a single self-contained file, and easily switch between either.
C++
81
star
6

quickrand

Quick Erlang Random Number Generation
Erlang
43
star
7

erlang_py

Erlang External Term Format for Python
Python
36
star
8

erlang_js

Erlang External Term Format for Javascript
JavaScript
34
star
9

erlang_term

Erlang Term Info
Erlang
34
star
10

erlbench

Erlang Performance Measurements
Erlang
34
star
11

erlang_ml

Erlang External Term Format for OCaml
OCaml
28
star
12

reltool_util

Erlang reltool utility functionality application
Erlang
26
star
13

varpool

Erlang Process Pools as a Local Variable
Erlang
19
star
14

erlang_go

Erlang External Term Format for Go
Go
19
star
15

cgroups

Erlang native cgroups interface
Erlang
12
star
16

sillymud

SillyMUD codebase as a CloudI Service
C
11
star
17

erlang_php

Erlang External Term Format for PHP
PHP
10
star
18

erlang_rb

Erlang External Term Format for Ruby
Ruby
10
star
19

syslog_socket

Erlang syslog Client Interface
Erlang
7
star
20

key2value

Erlang 2-way map
Erlang
7
star
21

supool

Erlang Process Pool as a Supervisor
Erlang
5
star
22

record_info_runtime

Parse transform for using record_info(size, _) and record_info(fields, _) during runtime
Erlang
5
star
23

nd_index

Erlang N-dimensional Index Iterator
Erlang
4
star
24

erlang_hs

Erlang External Term Format for Haskell
Haskell
4
star
25

erlang_pl

Erlang External Term Format for Perl
Perl
3
star
26

effects

An experimental C++ runtime effect system
C++
1
star
27

odroid_fish

Make service requests swim!
Python
1
star
28

blookup

Binary Lookup Data Structure
Erlang
1
star
29

odroid_display

Odroid-C1 Display Service for CloudI
C
1
star
30

exometer

Basic measurement objects and probe behavior (for https://github.com/CloudI/cloudi_service_monitoring)
Erlang
1
star
31

keys1value

Erlang set associative map for key lists
Erlang
1
star
32

unicode_data

Unicode for Erlang/Elixir
Erlang
1
star
33

lens

Erlang templates lens example
Erlang
1
star