Skip to main content

A fast and efficient trie-based collection for storing and searching millions of strings.

Project description

TRIE Module

A fast and efficient trie-based set for storing and searching millions of short strings.

Features

  • Add strings to the set quickly.
  • Search for strings in constant time complexity.
  • Iterate through stored strings in lexicographical order.
  • Support for prefix matching.
  • Case-insensitive search.
  • Export and import trie data to/from JSON.
  • Supports word deletion.

Installation

pip install fast_trie_set

Usage

from fast_trie import TRIE

# Initialize the Trie with a list of words
trie = TRIE(['hello', 'world', '!', ',', 'hen', 'hell'], case_insensitive=True)

# Add a word
trie.add('Help')

# Extend trie with a list of words
trie.extend(['HeLLo', 'WoRlD'])

# Check if a word exists
print('hello' in trie)  # True
print('unknown' not in trie)  # True

# Find index of a word
print(trie.find('hell'))  # Index of 'hell'

# Match words with a given prefix
print(list(trie.prefix_match('he')))  # ['hello', 'hen', 'hell', 'help']

# Delete a word
trie.delete('hell')
print(list(trie))  # ['hello', 'world', '!', ',', 'hen', 'help']

# Export the trie to a JSON file
trie.export("trie.json")

# Import a trie from a JSON file
imported_trie = TRIE.import_trie("trie.json", case_insensitive=True)
print(list(imported_trie))  # ['hello', 'world', '!', ',', 'hen', 'help']

License

MIT License. See LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_trie_set-0.6.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_trie_set-0.6.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file fast_trie_set-0.6.1.tar.gz.

File metadata

  • Download URL: fast_trie_set-0.6.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.10

File hashes

Hashes for fast_trie_set-0.6.1.tar.gz
Algorithm Hash digest
SHA256 ec0dd9c6ef791b4f74eee6b1825be3f39e0b206a6b81e988376b9e22d2af6496
MD5 20ecb65d6f10b8382ff413679da30e25
BLAKE2b-256 97f24071de7631bacf54ff5450ada09729c8ec582d389f74abd51166510c7f1f

See more details on using hashes here.

File details

Details for the file fast_trie_set-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: fast_trie_set-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.10

File hashes

Hashes for fast_trie_set-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 111d235160492a46c7dbc1fb1ba3caf9d877edfec5842497bda87b87ff9fe459
MD5 13582f57e557c61d8835bc158c7175c6
BLAKE2b-256 4132de3ec01aa3d0a2c90686f76815a67b281c919a7af1d62fc5e04bc2a5b3c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page