Giter Site home page Giter Site logo

Comments (2)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
A possible workaround can be -
                    if (properties.replaceDuplicateKey) {
                        bucketEntry[0] = key;
                        oldValue = bucketEntry[1];
                        bucketEntry[1] = value+", "+oldValue;
                    }
                    else{
                        bucketEntry[1] = value;
                    }

But this is not a good way to do so. I think  if there exist duplicate values 
then it will return an array other than the plain object.

Original comment by [email protected] on 13 Feb 2015 at 6:04

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
This is the expected behaviour. If you put a new value for an existing key, the 
value should always be replaced, which is how all hash table implementations 
that I've used work. The replaceDuplicateKey determines what happens to the key 
that is stored in that situation. The following example illustrates this:

var key1 = { foo: 1, name: "key1" }, key2 = { foo: 1, name: "key2" };

function keysEquals(k1, k2) {
    return k1.foo == k2.foo;
}

var hash1 = new Hashtable( { equals: keysEquals, replaceDuplicateKey: true } );
hash1.put(key1, 1);
hash1.put(key2, 2);
console.log(hash1.keys()[0].name); // key2

var hash2 = new Hashtable( { equals: keysEquals, replaceDuplicateKey: false } );
hash2.put(key1, 1);
hash2.put(key2, 2);
console.log(hash2.keys()[0].name); // key1

Original comment by [email protected] on 18 Feb 2015 at 11:26

  • Changed state: Invalid

from jshashtable.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.