Pre-release
This release is a pre-release and may not be stable for production use.
prefix-free-sorted-cowlist-set
A Python implementation of a prefix-free, sorted set of COWList, backed by a trie data structure for efficient prefix checking and maintenance of sorted order.
Features
- Prefix-Free Guarantee: Ensures no sequence in the set is a prefix of any other sequence
- Sorted Order: Maintains all COWList in lexicographical order
- Efficient Operations:
- O(k) time complexity for add/discard operations (where k is sequence length)
- Fast prefix checking via trie traversal
- Memory Efficient: Uses Copy-On-Write semantics for list storage
- Pythonic Interface: Implements both
MutableSetandSequenceprotocols
Installation
pip install prefix-free-sorted-cowlist-set
Usage
# coding=utf-8
from prefix_free_sorted_cowlist_set import PrefixFreeSortedCOWListSet
from cowlist import COWList
# Create a new set
pf_set = PrefixFreeSortedCOWListSet()
# Add sequences (returns True if successful)
assert pf_set.add(COWList([1, 2, 3])) # True
assert pf_set.add(COWList([1, 2, 4])) # True
assert pf_set.add(COWList([1, 3])) # True
# Try to add a prefix (will fail)
assert not pf_set.add(COWList([1, 2])) # False - violates prefix-free property
# Check membership
assert COWList([1, 2, 3]) in pf_set # True
# Iterate in sorted order
assert list(pf_set) == [COWList([1, 2, 3]), COWList([1, 2, 4]), COWList([1, 3])]
# Reverse iteration
assert list(reversed(pf_set)) == [COWList([1, 3]), COWList([1, 2, 4]), COWList([1, 2, 3])]
# Remove sequences
assert pf_set.discard(COWList([1, 2, 3]))
assert list(pf_set) == [COWList([1, 2, 4]), COWList([1, 3])]
# Length of set
assert len(pf_set) == 2
# Index access (sorted order)
assert pf_set[-1] == COWList([1, 3])
Use Cases
File System Paths
from prefix_free_sorted_cowlist_set import PrefixFreeSortedCOWListSet
from cowlist import COWList
# Store unique file paths where no path is a prefix of another
paths = PrefixFreeSortedCOWListSet()
paths.add(COWList(["usr", "local", "bin"]))
paths.add(COWList(["usr", "local", "lib"]))
# paths.add(COWList(["usr", "local"])) # This would fail - prefix violation
Domain Names
from prefix_free_sorted_cowlist_set import PrefixFreeSortedCOWListSet
from cowlist import COWList
# Store domain names ensuring no subdomain conflicts
domains = PrefixFreeSortedCOWListSet()
domains.add(COWList(["example", "com"]))
domains.add(COWList(["sub", "example", "com"]))
# domains.add(COWList(["example"])) # This would fail
Routing Tables
from prefix_free_sorted_cowlist_set import PrefixFreeSortedCOWListSet
from cowlist import COWList
# Network routing paths where no route should be a prefix of another
routes = PrefixFreeSortedCOWListSet()
routes.add(COWList([192, 168, 1, 0]))
routes.add(COWList([192, 168, 2, 0]))
API Reference
PrefixFreeSortedCOWListSet
Methods
add(cowlist: COWList[T]) -> bool: Add a COWList to the set if it doesn't violate the prefix-free propertydiscard(cowlist: COWList[T]) -> bool: Remove a COWList from the set if present__contains__(item: COWList[T]) -> bool: Check if a COWList is in the set__getitem__(index: int) -> COWList[T]: Get COWList at specified index (sorted order)__iter__() -> Iterator[COWList[T]]: Iterate over COWList in sorted order__len__() -> int: Get number of COWList objects in the set__reversed__() -> Iterator[COWList[T]]: Iterate in reverse sorted order
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Release files for prefix-free-sorted-cowlist-set 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prefix_free_sorted_cowlist_set-0.1.0a1.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prefix_free_sorted_cowlist_set-0.1.0a1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 11.9 kB
Release files / prefix_free_sorted_cowlist_set-0.1.0a1.tar.gz
| Download URL | prefix_free_sorted_cowlist_set-0.1.0a1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a181e2102172f4c489cf46774e692932390612e8ce0c7fd5b0682e87f38af7c
|
|
BLAKE2b-256 checksum How to use checksums |
a9866faec6f06e8036bc6c06b667ab56a629af66db73ec1aa907c7b6d80dd780
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / prefix_free_sorted_cowlist_set-0.1.0a1-py2.py3-none-any.whl
| Download URL | prefix_free_sorted_cowlist_set-0.1.0a1-py2.py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
162c3ad1665ebb58854004ddb84478ec0c093259846bd72e5239c770625fe899
|
|
BLAKE2b-256 checksum How to use checksums |
f7929b70ec50fbb462f1b23d7aaed1135cea0fc592c477892ff7b1a4e441cd62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|