uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Fix map implementation using wollokEquals and wollokHash (?) to compare keys #768

Open npasserini opened 8 years ago

npasserini commented 8 years ago

So we can avoid sequential key serching like:

    private def Object getInternalKey(WollokObject key) {
        wrapped.keySet.findFirst [ WollokObject itKey |
            itKey.wollokEquals(key)
        ]
    }
fdodino commented 8 years ago

Hi @npasserini Using TreeMap instead of HashMap only needs a WollokComparator already done (doesn't need wollokHash).

npasserini commented 8 years ago

Still TreeMaps requires that keys are sortable, which could be not true for several objects. Maybe we need a more profound discussion about the didactic implications of this:

Both maps make those decissions thinking about performance. Also for dictionaries the overwhelming most common cases are that simple objects sush as strings are used as keys, so those problems are uncommon. But sets of user defined objects are common.

So maybe I can rethink my initial idea. I mean, if we could come up with a dictionary implementation that is slower but avoids us to teach the student about hashcodes or ordering... could that be a trade off we are willing to do?

More elegant is that all this concerns are only necessary for objects that redefine equals but not hashCode. So a super hancy implementation of a wollok set (map) could use a fast implementation while there are only "good" elements (keys), and resort to a slower implementation when it is needed to support objects that redefine equals but not hashCode.

flbulgarelli commented 8 years ago

Still TreeMaps requires that keys are sortable, which could be not true for several objects. Maybe we need a more profound discussion about the didactic implications of this:

@npasserini :+1: