Leopold Toetsch wrote:
We need more vtables.

* INTVAL hash()

To properly support Python, we need:
- a hash PMC that isn't restricted to STRING* keys - low level hash code has AFAIK already all the necessary stuff, or mostly. I don't know, how much Python specific it really is, but Perl5's "hashing objects as strings" isn't really what we want AFAIK.
Anyway, every hashable PMC should have such a vtable slot to produce a unique and reproducable hash value according to the - well value - of that PMC. UT python SL.

I've been looking into Python's dict code (see links below), and it actually is pretty sweet. Everything is stored in a single flat array that doubles in size whenever it reaches 2/3 full.


Notable features of Python dicts:

Only things that are immutable are expected to have hash functions. Tuple, for example, does have a __hash__ function; list does not. Nor does dict. Unless Parrot has an equivalent notion, it will have to clone the key.

There also is interesting semantics with respect to values (or more precisely, the semantics of an assignment statement). At the moment pirate is consistent with Python on the following, but pie-thon is not:

  a=1
  d={"a":a}
  a=2
  print d

  a=[1]
  d={"a":a}
  a[0]=2
  print d

The "correct" result is:

  {'a': 1}
  {'a': [2]}

With pie-thon, the results are:

  {'a': 2}
  {'a': [2]}

- Sam Ruby

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/dictnotes.txt?view=markup
http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/dictobject.c?view=markup

Reply via email to