473,563 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lookup data structure that returns the previous element as well

I am looking for a data structure that I need to use as follows.
Suppose I am looking for node A. When I perform a lookup for node A I
also want information about the node previous to node A( as per the
lookup data structure ordering scheme). Is there anything that I could
use for this. Using a doubly linked list is not looking good as I can
have a large number of elements in my linked list.

Thanks in advance,
Peter
Nov 14 '05 #1
5 1800
On 2003-12-09, Peter <pe************ **@yahoo.com> wrote:
I am looking for a data structure that I need to use as follows.
Suppose I am looking for node A. When I perform a lookup for node A I
also want information about the node previous to node A( as per the
lookup data structure ordering scheme). Is there anything that I could
use for this. Using a doubly linked list is not looking good as I can
have a large number of elements in my linked list.


One common trick is to stash the previous node someplace in your lookup
datastructure.

struct foo {
struct foo_node *last;
struct foo_node_contai ner *container;
};

struct foo_node *
find_foo_node(s truct foo *foo_instance, const void *key)
{
struct foo_node *node_of_intere st;

node_of_interes t = container->find(container , key);
if (foo_instance->last) {
/*
* ...
* do something to node_of_interes t with info from last
* ...
*/
}

return foo_instance->last = node_of_interes t;
}

-- James
Nov 14 '05 #2
Peter wrote:

I am looking for a data structure that I need to use as follows.
Suppose I am looking for node A. When I perform a lookup for node A I
also want information about the node previous to node A( as per the
lookup data structure ordering scheme). Is there anything that I could
use for this. Using a doubly linked list is not looking good as I can
have a large number of elements in my linked list.


If there's a C question here, I'm failing to see it.
Well, maybe there is: If "previous" is a relation defined
by a key value in the node, you can maintain the collection
of nodes as a sorted array and look things up with bsearch().

Other algorithms certainly exist, and may be more
appropriate (you really haven't explained your problem in
any detail) -- but this is a language newsgroup, not an
algorithms newsgroup. Once you've settled on an approach,
come back here for help if you're having trouble implementing
it in C.

--
Er*********@sun .com
Nov 14 '05 #3
>Subject: lookup data structure that returns the previous element as well

I am looking for a data structure that I need to use as follows.
Suppose I am looking for node A. When I perform a lookup for node A I
also want information about the node previous to node A( as per the
lookup data structure ordering scheme). Is there anything that I could
use for this. Using a doubly linked list is not looking good as I can
have a large number of elements in my linked list.


Define 'previous'. If I suggested you a binary tree, 'previous' would be
ambiguous (previous in-order node -- or the node's parent).
I assume you mean the former, as you mention linked lists. Getting the previous
in-order element with a btree is a bit more complicated, but the Btree gives
you an all-around better performance than a linked list when having lots of
elements.


Jan Engelhardt
Nov 14 '05 #4
Jan Engelhardt <je*****@linux0 1.gwdg.de> writes:
Define 'previous'. If I suggested you a binary tree, 'previous' would be
ambiguous (previous in-order node -- or the node's parent).


I have never heard the word "previous" used to refer to a binary
tree node's parent.
Nov 14 '05 #5
>> Define 'previous'. If I suggested you a binary tree, 'previous' would be
ambiguous (previous in-order node -- or the node's parent).


I have never heard the word "previous" used to refer to a binary
tree node's parent.


When you run along a path, the previous [path] node is obviously the parent.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4870
by: Neal D. Becker | last post by:
I need a fairly small lookup table, and I'm wondering which data python data structure would be fastest. I could use a list, tuple, dictionary, numeric array, or maybe plain python array. The table would be indexed by simple integers and would be dense (filled).
0
1748
by: Fabian Kr?ger | last post by:
Hello, I got a weird problem and need your help and ideas... I´ve written an php application which imports data in XML format and writes this data to a MySQL database to have a faster access. The application uses Expat 1.95.7 via php to render the xml data. First everything seemed to work fine. But now I noticed that something
9
7018
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the lookup tables are not likely to change. Question 1: Should I include them in the backend (with rest of data) or the frontend?
4
3844
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system that doesn't offer dynamic memory allocation (to be clear: no malloc, no realloc), and with rather tight memory constraints. Writing my own...
26
7051
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of the structure inside the array. When I try this, an error about late assignment appears. Is it possible to assign a value to a structure field...
6
5928
by: Paul Delhanty | last post by:
Hi, I am converting an existing native C++ program making heavy use of STL to C#2.0 with STL usage replaced by the new generic collections. The conversion has gone well to the point where I am replacing an STL map instance by a System.Collections.Generic.SortedDictionary instance. In need the collection to be ordered, and to have...
9
6623
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its length is 642 bytes ( I have appended it to the end of this message). I suspect that the reason may have something to do with an incorrect declaration...
3
2373
by: dancole42 | last post by:
I'm self-taught in Access, and as such I'm missing large chunks of knowledge, so I'm hoping someone here with some training can help me. Right now I have an Invoice form with a Customer subform. Right now it's set up so that someone can enter a customer ID, say, 12345, into the invoice form and customer 12345's name, address, etc. shows...
3
5083
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.