X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8ECD49FAE4E for ; Wed, 3 May 2006 02:14:25 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 71494-09 for ; Wed, 3 May 2006 02:14:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tamu-relay.tamu.edu (smtp-relay.tamu.edu [165.91.22.120]) by postgresql.org (Postfix) with ESMTP id CB3FE9FA7B6 for ; Wed, 3 May 2006 02:14:09 -0300 (ADT) Received: from coe.tamu.edu (edsun.coe.tamu.edu [165.91.232.6]) by tamu-relay.tamu.edu (8.13.6/8.13.3) with ESMTP id k435EG2b073026; Wed, 3 May 2006 00:14:17 -0500 (CDT) (envelope-from bkim@coe.tamu.edu) Received: from coe.tamu.edu (coe.tamu.edu [165.91.232.6]) by coe.tamu.edu (8.11.7p2+Sun/8.11.7) with ESMTP id k435E4Q21851; Wed, 3 May 2006 00:14:04 -0500 (CDT) Date: Wed, 3 May 2006 00:14:04 -0500 (CDT) From: "Ben K." To: Guy Fraser cc: pgsql-sql@postgresql.org Subject: Re: LinkedList In-Reply-To: <1146239551.12641.210.camel@sigurd.incentre.net> Message-ID: References: <1146067158.23538.264.camel@state.g2switchworks.com> <1146239551.12641.210.camel@sigurd.incentre.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Received-SPF: pass (smtp-relay.tamu.edu: 165.91.232.6 is authenticated by a trusted mechanism) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/26 X-Sequence-Number: 25057 > The problem is that your way, there is no indicated way to determine > which node is which. For instance is you update any of your nodes > then the node list would be out of order and your list would not > work. I think the thinking is different here. The OP's list is ordered and has prev-next only, and there can be lists that are read only and/or ordered (like clickstream or a data stream out of multi-stream packets) and do not require insert. That's why I mentioned it's for traverse-only in my original post. (But I disagree with you about not being able to determine a node - since in sql it's possible to identify a row as long as it has unique values in fields, however they are named) > After I posted the message I realized there is another way to > do this without adding an extra field, and it would be a closer > example to how it is done in C. If you assigned the OID of the > previous and next nodes rather than arbitrary integer, you could > access each node independent of the order they are listed. > > I have not messed around much with OIDs. I am not sure if > OIDs change if an entry is updated. I understand oid doesn't change with update. But tables may or may not have oids. (can be created "without oids") I also came to appreciate the difference with C. In sql, there is a way to identify a row like I did, but in C it'd not be possible without the address (of course it's not like "impossible" but ...), so the linked list as in strict C-like sense would be perfect but may carry a different value here. (Since we already have the added layer of sql engines.) I agree your method would be better if we want to scale when insert or delete is needed. It'd be interesting to compare how the normal O() applies to sql - would updating n rows with one sql statement be equivalent to O(n) in C? Maybe a silly question but it came to my mind... > In C you would use a pointer to storage location of previous > and next "node" which is similar to using the OID. In some > cases it can be necessary to use pointers to pointers when > accessing variable length relocatable data, but that goes way > past what this thread is about. > The example I provided, is still feasible and alleviates all > unknowns at the expense of 4 bytes of storage for one integer > used as a fixed address for each node. > As long as it works in real world use. Without some way of addressing > each node, the idea of a linked list seems wrong, since a linked is > supposed to hold the address of the previous and or next item in the > list, assuming the data is always going to be correctly sorted so that > you can locate the next item by tupple number seems overly assumptive. > If it works for you great, your example may then be useful as a short > cut, but I don't believe in leaving things to chance when programming. Regards, Ben K. Developer http://benix.tamu.edu