Skip to content

Commit f148ad3

Browse files
committed
Notes on dict implementation
1 parent 20fb671 commit f148ad3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

notes.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Type ideas
4646
* Embed a zero sized struct with default implementations of all the methods to avoid interface bloat
4747
* would have a pointer to the start of the object so could do comparisons
4848
* however don't know anything about the object - can't call Type() for instance
49+
* could possibly use non-empty struct { *Type } and get that to provide Type() method
4950
* except for String/Int/Bool/Tuple/Float/Bytes and possibly some others...
5051
* can embed this default interface whether we do fat interfaces or not...
5152
* can have heirachies of embedding
@@ -101,6 +102,44 @@ __le__
101102
__lt__
102103
__ne__
103104

105+
dict
106+
====
107+
108+
Implementation notes
109+
110+
Implement __hash__. This should return an Int which in turn will
111+
convert to an int64 (either a py.Int or a py.BigInt.Int64()). Make
112+
py.BigInt.M__hash__ return a Py.Int and can use that to squash
113+
the return when it is an BigInt.
114+
115+
dict should have a .StringDict() method so can convert easily for
116+
argument passing etc.
117+
118+
Maybe dict should contain a StringDict() so if py.CheckString(Exact?)
119+
then can use the embedded StringDict which is what the majority of
120+
dict access is. Might complicate other things though.
121+
122+
Basic implementation is map[int64][]struct{key, value Object} where
123+
int64 is the hash. Types must implement __hash__ and __eq__ to be a
124+
key in a dict.
125+
126+
Would be much faster if __eq__ and __hash__ were on all types!
127+
128+
Idea: Each slice of objects in dictionary or set can be a SimpleDict
129+
or SimpleSet which is an O(n**2) Dict or Set. This could be the
130+
implementation for a few elements also if we can figure out how to
131+
switch implementation on the fly. Maybe with an interface...
132+
133+
Would like to be able to switch implementation on the fly from
134+
StringDict to SimpleDict to full Dict. Can we define an interface to
135+
make that possible? A dict type then becomes a pointer to an
136+
interface, or probably better a pointer to a struct with a mutex and a
137+
pointer to an interface.
138+
139+
140+
Lookup what go uses as hash key eg int and use that for gpython.
141+
Perhaps use a little bit of assembler to export the go hash routine.
142+
104143

105144
genpy
106145
=====

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy