Tables and hashes

2021-04-15 Thread timothee
=> PR

Tables and hashes

2021-04-09 Thread Araq
Yeah, I agree. It's a strange omission that `ref` doesn't have a default `hash` implementation. While we have users coming from Python who use too much `ref object`, Python's class construct also has reference semantics when put into a dictionary, so I assume this wouldn't be error-prone for any

Tables and hashes

2021-04-09 Thread ynfle
This is explicitly mentioned in the `tables` documentation

Tables and hashes

2021-04-09 Thread Stefan_Salewski
I know that docs, read it five years ago, and again early this morning. Made it not really more obvious for me. But OK, I can live with the fact that I have to define a hash() proc for my references.

Tables and hashes

2021-04-09 Thread Stefan_Salewski
No. In my initial post I explained that default equality operator == for references use the address of the instances, not the fields content, if we use == for two references. So it should be expected that for hashes of references, the content does not matter by default!

Tables and hashes

2021-04-09 Thread PMunch
Well most people would assume using an object (ref or otherwise) as the key for a table would use the hash of the data of the object, and not the reference of the object. So with the default you're imagining a lot of people are likely to have some strange bugs.

Tables and hashes

2021-04-09 Thread Stefan_Salewski
Not really related to my initial question, but Nim hashes works exactly like I assumed: import tables, hashes type V0 = ref object of RootRef i: int proc hash(v: V0): Hash = var h: Hash = 0 h = h !& addr(v[]).hash result = !$h

Tables and hashes

2021-04-09 Thread PMunch
Well a table is what is called a hash map. Essentially it has an array internally with N spots, then it hashes all the keys you want to put in and inserts the element (along with the hash or the key) into the array at position `hash mod N`. When you do a lookup the key is hashed again, you find

Tables and hashes

2021-04-09 Thread Stefan_Salewski
Sorry, I was not really asking what a hash map it. But thanks for the short summary. The core point is. A references can be seen as a managed pointer, which can be seen as an address, which is basically an integer value, with some restrictions maybe. So when hash() proc is predefined for intege

Tables and hashes

2021-04-09 Thread Stefan_Salewski
Im am still busy converting my old PCB rubberband router from Ruby to PCB. While getting it to compile was already some work, getting it to really work is a task for which I can not estimate the effort still... One larger issue are the tables -- I can not remember how they work in Ruby, and I s