@@ -46,6 +46,7 @@ Type ideas
46
46
* Embed a zero sized struct with default implementations of all the methods to avoid interface bloat
47
47
* would have a pointer to the start of the object so could do comparisons
48
48
* 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
49
50
* except for String/Int/Bool/Tuple/Float/Bytes and possibly some others...
50
51
* can embed this default interface whether we do fat interfaces or not...
51
52
* can have heirachies of embedding
@@ -101,6 +102,44 @@ __le__
101
102
__lt__
102
103
__ne__
103
104
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
+
104
143
105
144
genpy
106
145
=====
0 commit comments