🚀 Socket Launch Week 🚀 Day 3: Socket Acquires Coana.Learn More
Socket
Sign inDemoInstall
Socket

fast-trie-set

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-trie-set

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

0.6.1
PyPI
Maintainers
1

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.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts