data-structures

Is there one type of set-like data structure supporting merging in O(logn) time and k-th search in O(logn) time?(n is the size of this set)

Is there one type of set-like data structure supporting merging in O(logn) time and k-th element search in O(logn) time? n is the size of this set. ...

Is there an easy way to set up ASP.NET Membership tables in a custom Database?

ASP.NET Membership is just great as there are a ton of functionality right there to be used, and we don't need to change nothing at all. We can even create our own Provider based on Membership database, and that give us infinite possibilities, like as I don't like the Question/Answer I just use an email that is sent with a reset link. ...

Memory efficient int-int dict in Python

Hi, I need a memory efficient int-int dict in Python that would support the following operations in O(log n) time: d[k] = v # replace if present v = d[k] # None or a negative number if not present I need to hold ~250M pairs, so it really has to be tight. Do you happen to know a suitable implementation (Python 2.7)? EDIT Removed i...

Memory-efficient string-to-string map in Python (or C)

I need a memory-efficient data structure for for storing about a million key--value pairs, where keys are strings of about 80 bytes, and values are strings of about 200 bytes, the total key and value size being about 280MB. I also need efficient lookup of value by key, preferably a hash-map. The memory overhead should be as little as pos...

How can I sort many arrays according to one array?

I have a data structure like the following @colors = qw(red blond green); @numbers = qw(349 1234.5678 3.14159265); @hats = qw(fedora porkpie bowler); my %hash = (colors => \@colors, numbers => \@numbers, hats => \@hats); I want to sort this according to the values of one of the arrays, maintaining the association of parallel array ele...

In-memory data structure for compactly mapping billions of dictionary keys to values

I have billions of records (keys/values) that I want to compactly store in memory, and the only operation I need to support is looking up a value by its key. Keys and values are both small strings. The most important thing is how compressed the data structure is; it should use the internal structure of the keys in a deeper way than a sim...

How to implement an half-edge data structure in Haskell ?

For a description of the data structure see http://www.flipcode.com/archives/The_Half-Edge_Data_Structure.shtml http://www.cgal.org/Manual/latest/doc_html/cgal_manual/HalfedgeDS/Chapter_main.html An half-edge data structure involves cycles. is it possible to implement it in a functional language like Haskell ? are mutable reference...

Sorted array list in Java

I'm baffled that I can't find a quick answer to this. I'm essentially looking for a datastructure in Java which implements the java.util.List interface, but which stores its members in a sorted order. I know that you can use a normal ArrayList and use Collections.sort() on it, but I have a scenario where I am occasionally adding and of...

represent allowed status transitions graph in Perl

There is something like status changes check logic in our app. Currently checking is being handled by ugly if statement I want to replace it by transition matrix: my %allowed_status_changes = ( 1 => (2,5), 2 => (1,2,3,4,5), 3 => (4,2), 4 => (3,2), 5 => (), ); my $is_allowed_transition = ...

Convert and Print Structure contents to a form in Visual Basic

Hello, I am trying to print the contents of a structure onto a print page in Visual Basic(visual studio 2008). However my for each loop generates a conversion error? Could someone help me figure out whats wrong? Thanks Public Class Form1 Structure IncomeRecord Dim IDVal As Integer Dim HouseholdNum As Integer Dim YearlyInco...

startsWith() returning unexpected values

The class project has us reading in the title, artist and lyrics of 10,514 songs contained in a single text file. The current section of the project had us write an ordered unrolled linked list and run a search on the title field. The comparator was also written to sort the list by title. We have to keep track of the comparisons requi...

Why am i getting "warning: assignment from incompatible pointer type"? Double linked list in a struct array

Hi, I'm trying to make an implementation of a double linked list which connects to an array. The struct that makes the array contains the list's Head and Tail pointer. typedef struct myStruct{ int code; struct myStruct *Head; struct myStruct *Tail; }myStruct; myStruct MyArray[10]; Here's my double linked list: struct myList { ...

Spatial organisation of a group of blocks on a grid

I have a grid of cells (empty at beginning), and a collection of blocks which are rectangles or squares whose size are a multiple of a cell (for example, a block might be 2 cells by 3 cells). I won't know all the blocks in advance, but will have to place them as they arrive. In case anyone's wondering, this has to do with placing a bunch...

javascript datastructure question

I have an array: myArray = []; To which I am adding objects: data = []; myArray.push( { elem1: ..., elem2: data.push(...); } ); So, elem2 in the object contains an array. How can I, given myArray add new elements to the array in elem2? I tried the following: myArray[idx].elem2.push("new data"); But got an error saying tha...

What's a good way to manage a lot of loosely related components in F#?

I'm trying to translate an idea I had from OOP concepts to FP concepts, but I'm not quite sure how to best go about it. I want to have multiple collections of records, but have individual records linked across the collections. In C# I would probably use multiple Dictionary objects with an Entity-specific ID as a common key, so that giv...

Two-way Hash Table in Erlang

I'm trying to come up with a dictionary-like data structure that I can use in Erlang. The goal is to guarantee that all the values, as well as the keys, are unique. I can do it with explicit consistency checks after every modification, but I'm hoping there's an obscure type that does this for me. Is there one? If not, is there a better w...

database table - data structure design c++

hi, this may be a dumb question or asked many times, i searched for it but did not find a proper answer. What is exactly going on when we type on SQL engine "Create table xxxx" how to implement this one in c++, i mean how it creates a variable dynamicalyy "xxxx" and store the data in it. If i queried "select * from xxxx" how it go to ...

Is there any (unbounded) fair blocking queue in java?

Is there any implementation of blocking queue which guarantees fair take() operation if multiple consumers are removing element from the same queue. I checked LinkedBlockingQueue, LinkedTransferQueue and looks like both of them are unfair. ArrayBlockingQueue provides fair operation but its bounded. ...

How to best store lines in a kd-tree

I know kd-trees are traditionally used to store points, but I want to store lines instead. Would it be best to split the line at every intersection with the splitting of the kd-tree? or would storing just the end-points into kd-suffice for nearest neighbor finding? ...

Alternatives to Entity-Attribute-Value (EAV)?

Hi, Our database is designed based on EAV (Entity-Attribute-Value) model. Those who have worked with EAV models know all the crap that comes with for the purpose of flexibility. I asked my client about the reasons why using EAV model (flexibility), and their response was: Their entities change over time. So, today they may have a tabl...