This release is a pre-release and may not be stable for production use.
sorted-fractionally-indexed-cowlist-set
A Python package for managing a sorted, fractionally-indexed set of COWList containing elements within a given alphabet.
Motivation
Many applications (real-time collaborative editors, distributed ledgers, dynamic sorted tables) require the ability to insert an unlimited number of unique items "in between" others in a totally ordered collection. This library brings this power to Python, modeled after the "fractional indexing" algorithms used in CRDTs and scalable databases.
Features
- Infinite-density insertion: Always able to create new COWList between or after existing members (fractional indexing).
- Efficient membership, indexing, and iteration.
- Fully typed.
- Supports Python 2 and 3.
- No non-Python dependencies.
Perfect for collaborative editing, database indices, and any system requiring dynamic totally ordered unique keys.
Installation
pip install sorted-fractionally-indexed-cowlist-set
Usage
# coding=utf-8
from __future__ import print_function
from cowlist import COWList
from sorted_fractionally_indexed_cowlist_set import SortedFractionallyIndexedCOWListSet
BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
# Initialize with base58 (or your own custom alphabet)
s = SortedFractionallyIndexedCOWListSet(alphabet=BASE58_ALPHABET)
# Synthesize an initial COWList
initial = s.synthesize(index=0)
# Cannot reliably synthesize COWList smaller than all others
try:
s.synthesize(index=0)
except ValueError:
pass
# Add existing COWList
s.add(COWList('4fj8AiZ'))
s.add(COWList('X'))
# Edge: try to add an invalid COWList
# Notice uppercase I is NOT in BASE58!
try:
s.add(COWList('I'))
except ValueError:
pass
# Check membership
assert COWList('X') in s
# List all COWLists (iteration is in sorted order)
assert list(s) == [
initial,
COWList('4fj8AiZ'),
COWList('X')
]
# Support for sequence protocol
assert len(s) == 3
assert s[0] == initial
assert s[1] == COWList('4fj8AiZ')
# Fractional insertion
# Insert a new COWList "between" the first and second elements
mid = s.synthesize(index=1)
assert list(s) == [
initial,
mid,
COWList('4fj8AiZ'),
COWList('X')
]
# You can insert at back
back = s.synthesize(index=len(s))
assert list(s) == [
initial,
mid,
COWList('4fj8AiZ'),
COWList('X'),
back
]
# Reverse iteration (sorted high-to-low)
assert list(reversed(s)) == [
back,
COWList('X'),
COWList('4fj8AiZ'),
mid,
initial
]
# Discarding COWLists
s.discard(COWList('4fj8AiZ'))
s.discard(COWList('notpresent'))
assert list(s) == [
initial,
mid,
COWList('X'),
back
]
# Slicing like a sequence
# Returns a List[COWList]
assert s[1:4] == [
mid,
COWList('X'),
back
]
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Metadata
Release files for sorted-fractionally-indexed-cowlist-set 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sorted_fractionally_indexed_cowlist_set-0.1.0a0.tar.gz | 5.3 kB | Without provenance | Details for sorted_fractionally_indexed_cowlist_set-0.1.0a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sorted_fractionally_indexed_cowlist_set-0.1.0a0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for sorted_fractionally_indexed_cowlist_set-0.1.0a0-py2.py3-none-any.whl |
Total release size: 11.3 kB
Release files / sorted_fractionally_indexed_cowlist_set-0.1.0a0.tar.gz
| Download URL | sorted_fractionally_indexed_cowlist_set-0.1.0a0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
071cf6fe7473c67813105b4c0f6b8ab3bd779a22324511ce45866ab237adf215
|
|
BLAKE2b-256 checksum How to use checksums |
aa57362bd8d04e915d771acbbe906f5e256ceb134b79b560e1c2ca86092a6dbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / sorted_fractionally_indexed_cowlist_set-0.1.0a0-py2.py3-none-any.whl
| Download URL | sorted_fractionally_indexed_cowlist_set-0.1.0a0-py2.py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c9a80cdef62470451fef0343e94244e846e0d0c3b5416ab540643fed5fb10f97
|
|
BLAKE2b-256 checksum How to use checksums |
c1dfb92601ea1dba4fea905ff5dcdd92a4bf386f1338cccc46ecadc8bdcee281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for sorted-fractionally-indexed-cowlist-set 0.1.0a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.