data-structures

Data structure for Category

I am looking for a data structure to add,remove,get,find on categories. for example: books drama science fiction other Sports Cycling Golf Team Sports soccer football etc. I think about using tree from C5 for example, but it looks like it has only red-black trees. Any suggestions? ...

What are the Practical Differences Between "associate" and "indexed" Arrays in PHP?

The PHP array type is actually more akin to an an ordered map than a traditional C array. It's PHP's original general use data structure. The manual goes as far to say The indexed and associative array types are the same type in PHP, which can both contain integer and string indices. However, there's a lot of cases where built-in lang...

Fast dictonary in C without linear search

How can I make a fast dictonary ( String => Pointer and Int => Pointer ) in C without a linear search? I need a few ( or more ) lines of code, not a library, and it must be possible to use it in closed-source software (LGPL, ...). ...

Python: Set with only existance check?

I have a set of lots of big long strings that I want to do existence lookups for. I don't need the whole string ever to be saved. As far as i can tell, the set() actually stored the string which is eating up a lot of my memory. Does such a data structure exist? done = hash_only_set() while len(queue) > 0 : item = queue.pop() if i...

Converting integer identifiers to pointers

I have ID values of the type unsigned int. I need to map an Id to a pointer in constant time. Key Distribution: ID will have a value in the range of 0 to uint_max. Most of keys will be clustered into a single group, but there will be outliers. Implementation: I thought about using the C++ ext hash_map stuff, but I've heard thei...

Tree Data Structure

I am looking for a tree implementation... you can see the me previous question here. but I won't like to implement it myself, example functionalities needed: I need FindElement(node) I need GetParent(node) - will do the find again GetSubTreeFrom(node) - will find the element and return a subtree.. I know C5 - but all the trees there...

data structure to support lookup based on full key or part of key

I need to be able to lookup based on the full key or part of the key.. e.g. I might store keys like 10,20,30,40 11,12,30,40, 12,20,30,40 I want to be able to search for 10,20,30,40 or 20,30,40 What is the best data structure for achieving this..best for time. our programming language is Java..any pointers for open source projects wil...

Why on earth would anyone use set instead of unordered_set?

Please, excuse my ignorance about this subject :) C++0x is introducing unordered_set which is available in boost and many other places. What I understand is that unordered_set is hash table with O(1) lookup complexity. On the other hand, set is nothing but a tree with log(n) lookup complexity. Why on earth would anyone use set instead o...

In C++ how to return index of an array if user entered matches entered array ?

Hi All, I wanted to know how can we get the index of the array if the user entered array matches the input array ? For example: Input Array = [1,2,3,4] and user entered Array = [2,3] than I should get output as index where both array matches is 1. Guidance would be highly appreciated. ...

Fibonacci Heap Issue

I've been working on a Fibonacci Heap implementation in Java for about a week now. It's the implementation based off of the CLRS book. I wanted to see if I would get any performance boost using it in a side project I'm working on compared to Java's default PriorityQueue. [The default implementation in Java is array based, so much more l...

Data structures for plotting trends over time

Given a data stream of continuously arriving items containing a timestamp and text (e.g. a search engine's query log), how would you store the data so that you could efficiently retrieve totals over time to plot trend lines per term? A row-oriented database with tuples like (term, date, count) would work but would not scale with a large...

Representing a complex Perl data structure containing array references in Config::General

I have the following data structure in Perl code: my $config = { 'View::Mason' => { comp_root => [ [ 'teamsite' => 'root/teamsite' ], [ 'components' => 'root/components' ], ], }, }; I'm trying to represent this structure in a Config::General configuration file. So far I have: <Vi...

Should I generate a complex object in the database or data access layer?

I'm working on an application for one of our departments that contains medical data. It interfaces with a third party system that we have here. The object itself (a claim) isn't terribly complex, but due to the nature of the data and the organization of the database, retrieving the claim data is very complex. I cannot simply join all t...

C# Data Structure Like Dictionary But Without A Value

Is there any data structure in C# that is like a dictionary but that only has a key and doesn't have a value. I basically want a list of integers that I can quickly lookup and see if a certain value is in the list. Granted, for my current use, a List would not cause any performance problem, but it just doesn't seem to fit well with the...

linked list with no duplicates

I have the following code (correct for my simple tests) for a linked list for no duplicates, but I think it is a bit ugly. Could anyone recommend a cleaner way to handle the duplicate code? The current piece in question is: if( (val == cur->val) || (cur->next && (val == cur->next->val)) ) But I think that a better solution might exi...

simplifying data structures and condition statements in python code

I was wondering if there are any ways to simplify the following piece of Code. As you can see, there are numerous dicts being used as well as condition statements to weed out bad input data. Note that the trip rate values are not all inputed yet, the dicts are just copied and pasted for now EDIT In any of the rates, (x,y):z . x and y a...

Pointers to classes

Looking at example under "Pointers to classes" (very bottom) How is it that we can use the dot operatior here: CRectangle * d = new CRectangle[2]; ... d[1].set_values (7,8); if d is a pointer? Same question for the lines: cout << "d[0] area: " << d[0].area() << endl; cout << "d[1] area: " << d[1].area() << endl; Also, For...

Transform an array to several sql statements

Hi, I have a array that looks like this Array ( [provider] => Array ( [id] => provider1 [distribuitor] => Array ( [0] => Array ( [name] => distribuitor1 [machines] => Array ( ...

Approach to hold x most/least frequently occurring keyvaluepair in memory

I am being passed a series of keyvaluepair<string, uint> pairs, where the string represents a value and the uint represents how frequently the value has occurred in the source data. I need to be able to hold in memory the x most/least frequently occurring values, along with it's frequency. x in this case should be reasonably small but ...

Looking for space efficient algorithms and data structures

Preferably in Java. I am interested in implementations of data structures such as Sets and Maps, and algorithms such as sorting, that are memory-efficient, not necessarily fast. I could live with O(n^2) fetch and store if the amount of memory and number of allocations was low. Anything out there? ...