From: Patrick Maupin on
On Apr 4, 10:41 am, Patrick Maupin <pmau...(a)gmail.com> wrote:

> The primary differences between this structure and just haphazardly
> wiring up random objects into a directed graph are that (1) there may
> be some performance differences (but when the garbage collector has to
> figure out how to break cycles, these difference might or might not be
> in the direction you expect) and (2) with this structure, every object
> needs a globally unique name for indexing purposes.

(Just wanted to point out that I realize there aren't any cycles in
Steven's example data -- point (1) this paragraph was about the more
general use of the dict structure for general directed graphs.)

Pat
From: egbert on
On Sun, Apr 04, 2010 at 12:10:02PM +0000, Steven D'Aprano wrote:

> I can implement this tree using a flat dict:
>
> root = object()
> data = {root: ['Mammal', 'Reptile'],

What is the advantage, or thougth behind, using an instance
of object as the root of your flat tree ?
egbert

--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
========================================================================
From: Steven D'Aprano on
On Tue, 06 Apr 2010 19:16:05 +0200, egbert wrote:

> On Sun, Apr 04, 2010 at 12:10:02PM +0000, Steven D'Aprano wrote:
>
>> I can implement this tree using a flat dict:
>>
>> root = object()
>> data = {root: ['Mammal', 'Reptile'],
>
> What is the advantage, or thougth behind, using an instance of object as
> the root of your flat tree ? egbert

It's a known sentinel that can't possibly clash with an entry in the tree
except by deliberate action on the part of the caller.

I could have used None, or "root", or "this is a magic value that
probably won't clash with an entry in the tree", or -1 as a sentinel
instead, but they all risk accidental clashes with tree entries.



--
Steven
From: Lie Ryan on
On 04/07/10 14:18, Steven D'Aprano wrote:
> I could have used None, or "root", or "this is a magic value that
> probably won't clash with an entry in the tree", or -1 as a sentinel
> instead, but they all risk accidental clashes with tree entries.

Especially when you want to consider the possibility of inserting the
data structure inside the data structure itself.