--ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Rick DeNatale: > On Sun, Mar 29, 2009 at 12:05 PM, Shot (Piotr Szotkowski) <shot / hot.pl>wrote: >> class Graph >> def initialize enum >> @vertices = {} >> enum.each { |vertex| @vertices[vertex] = nil } >> end >> end > Why bother? The only reason I can thing of is that you want to use > @vertices.keys to get the collection of vertices, but why be indirect. > class Graph > def initialize(enum) > @vertices = enum > @labels = {} > end > end > @labels[anything] will return nil if anything isn't a key. Right, I was thinking about this approach on and off all day today, actually. :) The catch is Il be doing various things to this graph, like merging vertices together, grouping them by their labels (graph colouring), and doing similar operations on (labeled) edges. While I do like the cleanliness of the approach with @vertices being just a Set, @edges being just a Set of two-element Sets, and there being two additional Hashes for vertex and edge labels, I not sure I want the overhead of making sure there aren any leftover keys in the label Hashes after the graph drops some of its edges/vertices in other words, anytime I delete a vertex or an edge I”Ēd have to delete it from two places (either that, or anytime I query the labels I”Ēd have to make sure I”Ēm filtering out no-longer-existing vertices/edges which is even uglier). Note: I do know about GRATR, but it seems unmaintained; I found (granted, minor) bugs in it by simply requiring it with warnings enabled, and it requires (again, minor) patching to get it working with Ruby 1.9, but my patches to fix both are ignored (and there haven”Ēt been a relase for a year and a half). I would also use just a tiny fraction of GRATR”Ēs functionality, so it”Ēs simpler for me to have my own Graph class (and be able to easily RubyInline parts of it if/when I need the performance). ”½ Shot -- Is your keyboard jammed, or are you just writing Haskell? [Avdi Grimm] --ReaqsoxgOBHFXBhH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAknP0soACgkQi/mCfdEo8UpvRwCgqZdP/EaCHyS3RLMl3CnGaBoL +yUAoJoY8aPYIFDfuAFuyaqHeCQOGgzH ad -----END PGP SIGNATURE----- --ReaqsoxgOBHFXBhH--