DAZ wrote: > On Dec 28, 8:07�pm, Mark Reginald James <m...@bigpond.net.au> wrote: > >> One alternative is to make the ancestor array a string key >> to each record ("abe|homer|bart"), allowing instant retrieval. > > This seems like a relatively good idea, could have a string-key called > family_tree or something and just do find_by_family_tree("abe|homer| > bart") > This doesn't quite feel right - it seems like the only info you should > need to keep is a person's parent (from which you can then find their > parent and so forth). It might also lead to some very long strings > eventually!
I tend to like this idea as well, and is probably what I would do. The caching of the ancestry would seem to be the most efficient. However, there is one change I would make. I would reverse the ancestry so it would be ("bart|homer|abe"). Doing this would make string comparisons more efficient because you are looking for "bart" so having "bart" at the beginning of the string may slightly increase the string comparison efficiency. > This doesn't quite feel right - it seems like the only info you should > need to keep is a person's parent (from which you can then find their > parent and so forth). It might also lead to some very long strings > eventually! This, however, I don't agree with. You need the full ancestry to whatever the "root" objects is. The idea is to make one comparison with no joins. The only way to do that I can think of is to have all the information available at the row level. If you end up with a very deep hierarchy, which would result in very long strings, you could consider hashing the strings. This way you would have a consistent length string to compare. Example MD5 Hash: bart|homer|abe = a92b11363ef020716f1ce3104e0cb0d8 (32 chars) bart|homer|abe|john|william|ted|sam|joeseph|adam|bart|bill|jack = ff2f4ad181a029935b89a36c7cd1dfbe (32 chars) Obviously in some cases your losing rather than gaining, but at least the string is consistent in length no matter how long the input string becomes. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---