Skip to content

Commit

Permalink
fix: doc + CI
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Aug 30, 2023
1 parent 6c75746 commit 13b2207
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Build wheels
run: python -m cibuildwheel
env:
CIBW_SKIP: "cp36-* cp-312*" # skip 3.6 and 3.12 wheels
CIBW_SKIP: "cp36-* cp312*" # skip 3.6 and 3.12 wheels
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
- uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Make sure ``pytest`` is installed and run

$ python -m pytest

from the source checkout. Tests should pass under Python 2.7,
3.4 and newer.
from the source checkout. Tests should pass under Python 3.7 and newer.

In order to run benchmarks, type

Expand Down
44 changes: 22 additions & 22 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ marisa_trie.Trie
Create a new trie from a list of keys::

>>> import marisa_trie
>>> trie = marisa_trie.Trie([u'key1', u'key2', u'key12'])
>>> trie = marisa_trie.Trie(["key1", "key2", "key12"])

Check if a key is present::

>>> u'key1' in trie
>>> "key1" in trie
True
>>> u'key20' in trie
>>> "key20" in trie
False

Each key is assigned an unique ID from 0 to (n - 1), where n is the
number of keys in a trie::

>>> trie[u'key2']
>>> trie["key2"]
1

Note that you can't assign a value to a ``marisa_trie.Trie`` key,
Expand All @@ -44,19 +44,19 @@ but can use the returned ID to store values in a separate data structure
An ID can be mapped back to the corresponding key:

>>> trie.restore_key(1)
u'key2'
"key2"

Query a trie

* Find all trie keys which are prefixes of a given key::

>>> trie.prefixes(u'key12')
[u'key1', u'key12']
>>> trie.prefixes("key12")
["key1", "key12"]

* Find all trie keys which start with a given prefix::

>> trie.keys(u'key1')
[u'key1', u'key12']
>> trie.keys("key1")
["key1", "key12"]

* The latter is complemented by :meth:`~marisa_trie.Trie.items` which
returns all matching ``(key, ID)`` pairs.
Expand All @@ -74,7 +74,7 @@ marisa_trie.RecordTrie

Create a new trie from a list of ``(key, data)`` pairs::

>>> keys = [u'foo', u'bar', u'foobar', u'foo']
>>> keys = ["foo", "bar", "foobar", "foo"]
>>> values = [(1, 2), (2, 1), (3, 3), (2, 1)]
>>> fmt = "<HH" # two short integers.
>>> trie = marisa_trie.RecordTrie(fmt, zip(keys, values))
Expand All @@ -84,30 +84,30 @@ look at available `format strings <https://docs.python.org/3/library/struct.html

Check if a key is present::

>>> u'foo' in trie
>>> "foo" in trie
True
>>> u'spam' in trie
>>> "spam" in trie
False

``marisa_trie.RecordTrie`` allows duplicate keys. Therefore ``__getitem__`` and
``get`` return a list of values.

>>> trie[u'bar']
>>> trie["bar"]
[(2, 1)]
>>> trie[u'foo']
>>> trie["foo"]
[(1, 2), (2, 1)]
>>> trie.get(u'bar', 123)
>>> trie.get("bar", 123)
[(2, 1)]
>>> trie.get(u'BAAR', 123) # default value.
>>> trie.get("BAAR", 123) # default value.
123

Similarly, :meth:`~marisa_trie.RecordTrie.keys` and
:meth:`~marisa_trie.RecordTrie.items` take into account key multiplicities::

>> trie.keys(u'fo')
[u'foo', u'foo', u'foobar']
>> trie.items(u'fo')
[(u'foo', (1, 2)), (u'foo', (2, 1)), (u'foobar', (3, 3))]
>> trie.keys("fo")
["foo", "foo", "foobar"]
>> trie.items("fo")
[("foo", (1, 2)), ("foo", (2, 1)), ("foobar", (3, 3))]


marisa_trie.BytesTrie
Expand All @@ -116,10 +116,10 @@ marisa_trie.BytesTrie
``BytesTrie`` is similar to ``RecordTrie``, but the values are raw bytes,
not tuples::

>>> keys = [u'foo', u'bar', u'foobar', u'foo']
>>> keys = ["foo", "bar", "foobar", "foo"]
>>> values = [b'foo-value', b'bar-value', b'foobar-value', b'foo-value2']
>>> trie = marisa_trie.BytesTrie(zip(keys, values))
>>> trie[u'bar']
>>> trie["bar"]
[b'bar-value']


Expand Down

0 comments on commit 13b2207

Please sign in to comment.