[WIP] Implement dict to receive Object as key by HyeockJinKim · Pull Request #119 · go-python/gpython
Repository navigation
[WIP] Implement dict to receive Object as key - #119
Open
HyeockJinKim wants to merge 1 commit into go-python:main from HyeockJinKim:issue118
Open
[WIP] Implement dict to receive Object as key #119 HyeockJinKim wants to merge 1 commit into go-python:main from HyeockJinKim:issue118
Conversation
HyeockJinKim commented Oct 19, 2019
Copy link Copy Markdown
Contributor
Implement dict struct that takes Object as key
store key and value in array together so that dict is ordered
Issue #118
Implement dict to receive Object as key
9e2f6ab
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-io
commented
Oct 19, 2019
·
edited by codecov
Bot
Loading
Copy link Copy Markdown
Codecov Report❌ Patch coverage is
@@ 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 .
|
HyeockJinKim commented Oct 19, 2019
Copy link Copy Markdown
Contributor
Author
|
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. |
View reviewed changes
ncw left a comment
Copy link Copy Markdown
Collaborator
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
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.
Comment thread py/dict.go| type StringDict map[string]Object | ||
|
|
||
| type Dict struct { | ||
| keys map[Object]int |