mauriciosantos / Buckets-JS

A complete, fully tested and documented data structure library written in pure JavaScript.
MIT License
1.25k stars 112 forks source link

Adds a MultiBag data structure #4

Closed nvlbg closed 11 years ago

nvlbg commented 11 years ago

That's a data structure that I needed in a project I'm working on. I couldn't think of a way to use another structure from the existing ones, so I created this. I know that there aren't any tests or documentation strings. I'll write some if you think that this is a data structure that needs to be with the original buckets :)

mauriciosantos commented 11 years ago

Hi. Why cant you use a bag instead?

nvlbg commented 11 years ago

Actually this "MultiBag" is still not what I need. There will be some changes, but the basic idea is that I need a structure to store different elements, though the passed toString function might return the same key for them. Bag assumes that the element is the same. I thought maybe MultiDictionary might do it, but it had some missing functionality like forEach, so I thought I could create this "special" structure for my case. I'll return soon with more info.

mauriciosantos commented 11 years ago

In that case, you can simply write a foreach implementation for a multidictionary.

nvlbg commented 11 years ago

Well, another problem with MultiDictionary is that it uses arrays (for performance). In my case using dictionary of Sets with 2 toString functions solved the problem. I guess my case is really special and maybe this structure does not belong with the other ones. Check it out, and close the pull request if you think so :)

mauriciosantos commented 11 years ago

Sorry, but it is a really special case.