| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Implement dict struct that takes Object as key store key and value in array together so that dict is ordered Issue go-python#118
Codecov Report❌ Patch coverage is 0% with 108 lines in your changes missing coverage. Please review.
@@ Coverage Diff @@
## main #119 +/- ##
==========================================
- Coverage 72.85% 72.20% -0.66%
==========================================
Files 60 60
Lines 11949 12057 +108
==========================================
Hits 8706 8706
- Misses 2709 2815 +106
- Partials 534 536 +2 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
|
Since Hash is not implemented properly in gpython, I'm going to implement a dict that takes an Object as a key first. So, even if an object representing the same value comes in as key, the value is not found correctly. This can break the test code, so instead of getting rid of StringDict, I will fully implement Dict and replace StringDict with Dict. |
Sorry, something went wrong.
There was a problem hiding this comment.
I put some notes inline...
Making a Dict is quite a dififcult thing to do (probably why I didn't do it originally!)
Perhaps the thing to do to start with would be to make one with a simple internal structure which is just
type keyValue {
key Object
value Object
}
type Dict struct {
kvs []keyValue
}And make that work. Yes it won't be very efficient if there are lots of keys, but it should enable us to get the interface right, then we can work on optimizing it.
I note that in go1.14 the go team will expose the internal hashing function which would make implementing this much easier.
Sorry, something went wrong.
| type StringDict map[string]Object | ||
|
|
||
| type Dict struct { | ||
| keys map[Object]int |
There was a problem hiding this comment.
I don't think this is the right representation alas...
Putting the Object as the key means that you are relying on how Go compares interfaces. It does this with a shallow compare. An interface is basically
so comparing two interfaces just compares the pointer to type and pointer to data - it doesn't compare the data.
This means that you could insert two objects eg py.String("hello") and py.String("hello") and these would both get inserted into the dictionary.
I think what we want as the key is
And the values need to be a []Object (because different objects can have the same hash).
Sorry, something went wrong.
There was a problem hiding this comment.
There is no hash implementation, so I've got Object as key now.
We only receive hash values as key values. so I'm going to get int as the key.
What do you think about this way?
type Dict struct {
keys map[int]int // int key
Sorry, something went wrong.
There was a problem hiding this comment.
I think maybe we should try the really simple version first, then we can make it more efficient later
type dictEntry struct {
key Object
value Object
}
type Dict struct {
entries []dictEntry
}
Sorry, something went wrong.
There was a problem hiding this comment.
@ncw, to be nit-picky, the way py.String is currently implemented, I believe this would work.
see:
https://play.golang.org/p/bDvOEmkim6r
(ie: py.String just contains values and no pointers.)
but ok with going with the KISS version first.
Sorry, something went wrong.
There was a problem hiding this comment.
Indeed! The problem comes when the py.Object interface is satisfied with a pointer: https://play.golang.org/p/vf4dGmh0Gb4
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Implement dict struct that takes Object as key
store key and value in array together so that dict is ordered
Issue #118