pikasTech / PikaPython

An ultra-lightweight Python interpreter that runs with only 4KB of RAM, zero dependencies. It is ready to use out of the box without any configuration required and easy to extend with C. Similar project: MicroPython, JerryScript.
http://pikapython.com/
MIT License
1.45k stars 132 forks source link

字典的实现似乎有问题 #325

Closed blueloveTH closed 4 months ago

blueloveTH commented 11 months ago

commit id:893972bf4f7f8d65e1d01acf22c574cadf176bc4 系统:linux

pika

~~~/ POWERED BY \~~~
~  pikascript.com  ~
~~~~~~~~~~~~~~~~~~~~
hello pikascript
>>> x = {}
>>> x["a635000"] = 1
>>> x["a10000751"] = 2
>>> x
{'a10000751': 2}
>>> 

>>> a635000 = 'hello'
>>> a635000
'hello'
>>> a10000751 = 123
>>> a635000  # 写入了错误的变量
123
>>> 

cpython

>>> x = {}
>>> x["a635000"] = 1
>>> x["a10000751"] = 2
>>> x
{'a635000': 1, 'a10000751': 2}
>>>
blueloveTH commented 11 months ago

另外字典某些操作(例如删除)的时间复杂度似乎是O(n),而不是O(1)

pikasTech commented 11 months ago

你这是找了两个times33 hash冲突的字串吗,目前确实没有处理hash冲突,另外复杂度确实是O(n)

blueloveTH commented 11 months ago

还有

a = {}
b = ["1"]
a[b[0]] = 2

没记错的话这个会报一个setitem not defined的错误