comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Generic Embedded List Nodes
Date: Sun, 19 Jun 2016 19:42:11 -0700 (PDT)
Date: 2016-06-19T19:42:11-07:00	[thread overview]
Message-ID: <fcef381c-b0c0-4c53-9b99-012b7442a532@googlegroups.com> (raw)
In-Reply-To: <nk6vma$gfp$1@gioia.aioe.org>

On Sunday, 19 June 2016 16:35:32 UTC-4, Dmitry A. Kazakov  wrote:
> On 2016-06-19 22:13, Warren wrote:
> > On Sunday, 19 June 2016 15:04:05 UTC-4, Dmitry A. Kazakov  wrote:
> >> Maybe I don't understand the problem, but it seems you want externally
> >> linked objects that themselves were of any type.
> >
> > Close, but not quite. I had been toying with the idea that each node
> > point back to the containing object, but I've dropped that clumsy idea now.
> 
> You don't need that as you can calculate it from the object address. You 
> know the element head size and the alignment of the object (from 
> Allocate). This gives you the offset.

With the embedded list nodes, the calculation is a little different, but done along the same lines. You take the Node address and subtract to get to the containing object. But this design means you only allocate ONE object for list node and object together.

Like I've said in the beginning, I am only considering embedded list nodes for higher performance reasons. The embedded list operations are so simple they can be inlined with virtually no code or performance penalty.

> >> The best way to do it is IMO a custom memory pool.
> >
> > The problem I have with that is performance. For example deleting a
> > node from a list.
> >
> > procedure Delete
> >           (  Brand     : List_Identification_Type;
> >              Container : in out Web;
> >              Element   : in out Node
> >           );
> >
> > To delete the node, in the worst case, requires traversing the
> > entire  list. My lists can be 30,000+ long.
> 
> No, doubly-linked list deletion is O(1).

Ok you're tracking the link in Element, which is fine. However, your Element also needs a reference to the separately allocated object (which is a problem for me). This requires two allocations instead of one. 

I only need to insert head, traversal and delete. That's it!

> > In the embedded node case, I already have direct access to the
> > affected link node. To remove the node from a list I simply say:
> >
> >     R.Link_Node.Unlink;
> 
> The operation Delete has the list head parameter (Container) not for 
> traversing the list, but for modifying the list head if the first 
> element is deleted from the list.

> If you don't have it, you must maintain a dedicated list head element 
> with no object attached. That is a less safe and clean because it 
> ultimately leads to run-time type checks in the client code.

I agree with the dedicated list head statement, but not the "less safe" part. You either have container or you have a list head (each represents one list, though yours potentially several). 

There is nothing to check about a list head- you simply begin there. If you have no "head.next", you have an empty list.

Warren

  reply	other threads:[~2016-06-20  2:42 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 22:52 Generic Embedded List Nodes Warren
2016-06-18 23:40 ` Jeffrey R. Carter
2016-06-19  2:15   ` Warren
2016-06-19  3:04     ` Jeffrey R. Carter
2016-06-19  2:14 ` Jeremiah
2016-06-19  2:21   ` Warren
2016-06-19  2:50     ` Warren
2016-06-19  4:45       ` Simon Wright
2016-06-19 18:27         ` Warren
2016-06-19 19:04           ` Dmitry A. Kazakov
2016-06-19 20:13             ` Warren
2016-06-19 20:35               ` Dmitry A. Kazakov
2016-06-20  2:42                 ` Warren [this message]
2016-06-20  7:25                   ` Dmitry A. Kazakov
2016-06-20 12:26                     ` Warren
2016-06-20 19:33                       ` Niklas Holsti
2016-06-21  2:20                         ` Warren
2016-06-21  5:52                           ` Niklas Holsti
2016-06-21  7:15                             ` Dmitry A. Kazakov
2016-06-21 18:54                               ` Niklas Holsti
2016-06-21 19:54                                 ` Dmitry A. Kazakov
2016-06-21 10:31                             ` Warren
2016-06-21 17:13                               ` Jeffrey R. Carter
2016-06-21 18:56                                 ` Niklas Holsti
2016-06-21 20:13                                   ` Warren
2016-06-21 21:38                               ` Niklas Holsti
2016-06-23  2:12                                 ` Warren
2016-06-23  8:19                                   ` Niklas Holsti
2016-06-23 12:37                                     ` Warren
2016-06-23 15:36                                       ` Niklas Holsti
2016-06-24  1:55                                         ` Warren
2016-06-24 12:49                                         ` Warren
2016-06-25  5:50                                           ` Niklas Holsti
2016-06-26  1:36                                             ` Warren
2016-07-01 13:49                                             ` Warren
2016-07-01 16:28                                               ` Warren
2016-06-24 20:25                                         ` Warren
2016-06-22 13:01                               ` G.B.
2016-06-23  2:30                                 ` Warren
2016-06-20  6:08 ` Niklas Holsti
2016-06-20 12:20   ` Warren
2016-06-20 19:47 ` Shark8
2016-06-21  2:28   ` Warren
2016-06-21  7:21     ` Dmitry A. Kazakov
2016-06-21 10:32       ` Warren
2016-06-21 11:56         ` Dmitry A. Kazakov
2016-06-21 13:39           ` Warren
2016-06-21 14:04             ` Dmitry A. Kazakov
2016-06-23  0:37     ` Randy Brukardt
2016-06-23  2:25       ` Warren
2016-07-01 19:50 ` brbarkstrom
2016-07-02  1:55   ` Warren
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox