# Creating a true Map implementation with object equality (rant!)

**URL:** <https://forum.kirupa.com/t/creating-a-true-map-implementation-with-object-equality-rant/301405>\
**Category:** flash\
**Created:** [December 8, 2009, 11:54pm UTC](https://forum.kirupa.com/t/creating-a-true-map-implementation-with-object-equality-rant/301405 "2009-12-08T23:54:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonnyR](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@JonnyR](https://forum.kirupa.com/u/JonnyR)\
**Post date:** [December 8, 2009, 11:54pm UTC](https://forum.kirupa.com/t/creating-a-true-map-implementation-with-object-equality-rant/301405/1 "2009-12-08T23:54:48Z")

</div>

Afternoon chaps,

I’ve been spending some of my spare time working a set of collections for ActionScript 3 but I’ve hit a pretty serious roadblock thanks for the way ActionScript 3 handles equality checks inside Dictionary Objects.

When you compare a key in a dictionary, ActionScript uses the === operator to perform the comparison, this has a bit of a nasty side effect whereby only references to the same instance will resolve true and not objects of equality. Here’s what I mean:

```auto

const jonny1 : Person = new Person("jonny", 26);
const jonny2 : Person = new Person("jonny", 26);

const table : Dictionary = new Dictionary();
table[jonny1] = "That's me";

trace(table[jonny1]) // traces: "That's me"
trace(table[jonny2]) // traces: undefined.

```

[This stackoverflow post](http://stackoverflow.com/questions/51007/lack-of-operator-overloading-in-actionscript-3-0) sums it up pretty well. The way I am attempting to combat this is to provide an Equalizer interface which looks like this:

```auto

public interface Equalizer
{
    function equals(object : Object) : Boolean;
}

```

This allows to to perform an instanceOf-esq. check whenever I need to perform an equality operation inside my collections (falling back on the === operator when the object doesn’t support Equalizer); however, this doesn’t get around the fact that my underlying datastructure (the Dictionary Object) has no knowledge of this.

The way I am currently working around the issue is by iterating through all the keys in the dictionay and performing the equality check whenever I perform a containsKey() or get() operation - however, this pretty much defeats the entire point of a hashtable (cheap lookup operations).

If anyone has any views on the this, or a suggestion on how to implement a custom hashing algorythm (so I can replace the Dictionary instance with a “pure” hashtable) I’d love to chat about it!
