Comments (6)
Hi @superbobry,
I'm fine with adding __eq__
and __ne__
methods to Trie and other classes; pull requests are welcome :)
As for the hash, it looks like a consequence of a free list-based allocation indeed; two objects that are in memory at the same time are getting different hashes:
In [7]: from marisa_trie import Trie
In [8]: trie1 = Trie()
In [9]: trie2 = Trie()
In [10]: hash(trie1)
Out[10]: 281853959
In [11]: hash(trie2)
Out[11]: 281853967
from marisa-trie.
I'll try to submit a PR during the weekend.
two objects that are in memory at the same time are getting different hashes
I can add __hash__
as well, if it's ok with you.
from marisa-trie.
Thanks!
I think adding __hash__
is not necessary - what problem adding it solves? Current implementation doesn't e.g. affect dict collisions because hash is the same only for objects which are not alive at the same time.
from marisa-trie.
Good point. Having a trie as a dictionary key doesn't make much sense anyway :)
from marisa-trie.
There's one more edge-case: Trie
implements __getitem__
and doesn't override __iter__
. This (unfortunately) makes it iterable in CPython:
>>> t = Trie()
>>> iter(t)
<iterator object at 0x102939f28>
>>> for key in t:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument 'key' has incorrect type (expected str, got int)
Is it possible to make the Trie
yield keys in __iter__
just like dict
does?
from marisa-trie.
Ouch. Didn't know about that Python feature. Overriding __iter__
to return keys makes sense.
from marisa-trie.
Related Issues (20)
- Removal of has_keys_with_prefix Method HOT 1
- Build not working with Python 3.13.0b1 HOT 2
- Generated wheel names on PyPi don't match setuptools format requirements
- No bug - just a thanks
- 'marisa_trie.Trie' object does not support item assignment HOT 3
- libmarisa-trie fails on macOS Big Sur and Python 3.8 HOT 1
- no marisa
- Build under Python 3.9 failed HOT 2
- [INFO] New repository HOT 5
- Dropping support for Python 3.4 and 3.5?
- Drop support for Python 2.7? HOT 3
- marisa-trie==0.7.7 listed on PyPI but unavailable for installation HOT 6
- how to insert new node? HOT 4
- Can't install HOT 1
- Unable to add string values to RecordTrie
- Python 3.11 support HOT 7
- How to build from source?
- Seems like python 3.12 is not supported HOT 3
- API docs are empty
- Test failures on armv7 and armhf, Bus error (core dumped) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marisa-trie.