Insertion and deletions. But I would like to hear your idea anyway. Always good to hear ideas :)
On Sat, Jun 26, 2010 at 7:58 PM, Garth Sheldon-Coulson <g...@mit.edu> wrote: > Are there going to be a lot of deletions from the set? Or mostly > insertions? > > If it's mostly insertions (or if it's just a static data structure that > stays the same once built) then I think I can help. > > On Sat, Jun 26, 2010 at 9:01 AM, Nicolas Oury <nicolas.o...@gmail.com>wrote: > >> Dear all, >> >> for a project, I need a data structure to represent finite distribution, >> that is a set of elements, each of which having a mass in the set, and two >> functions: >> >> - total-mass : the sum of the masses of each element >> - draw : return an element with a probability proportional to its mass >> >> I currently use the simple idea : a Persistent Hash Map from elt to mass: >> - the total-mass is the reduce of (+ . second) >> - drawing is choosing a random-number between 0 and the total-mass and >> looping through the seq, to look for the corresponding element. >> >> Both operation are linear in the number of elements. This is a problem, >> because these sets tend to be quite big in my project. >> >> I think that if I used a HashTrie with total-mass cached in each node, >> total-mass would be in constant time and draw in log time. >> >> So here is my question : does anyone has, for example for the "clojure in >> clojure" project, a sketch of an implementation of PersistentHashMap >> in clojure itself? (I would be happy to contribute, if it needs more >> work). >> Or has anyone a better idea that mine to have drawable sets? >> >> Thanks for your help, >> >> Best regards, >> >> Nicolas. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clojure@googlegroups.com >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en