data-structures

Tree (directed acyclic graph) implementation

I require a tree / directed acyclic graph implementation something like this: public class TreeNode<K, V> { private K key; // 'key' for this node, always present private V value; // 'value' for this node, doesn't have to be set private TreeNode<K, V> parent; private Set<TreeNode<K, V>> children; } There is no sortin...

What are the most useful data structures to know inside out?

I'm interested in finding out what people would consider the most useful data structures to know in programming. What data structure do you find yourself using all the time? Answers to this post should help new programmers interested in finding a useful data structure for their problem. Answers should probably include the data structur...

Java: print_r?

Hi guys, last time I asked how to populate a data structure here. Now I would like to know if there's something in Java, like the print_r I use in PHP, to represent what I have populated in the Maps and lists without having to do my own algorithm. Any ideas? ...

How to shift items in an array?

I have an array of items that are time sensitive. After an amount of time, the last item needs to fall off and a new item is put at the beginning. What is the best way to do this? ...

Disk-backed STL container classes?

I enjoy developing algorithms using the STL, however, I have this recurring problem where my data sets are too large for the heap. I have been searching for drop-in replacements for STL containers and algorithms which are disk-backed, i.e. the data structures on stored on disk rather than the heap. A friend recently pointed me toward...

Why are entries in addition order in a .Net Dictionary?

I just saw this behaviour and I'm a bit surprised by it... If I add 3 or 4 elements to a Dictionary, and then do a "For Each" to get all the keys, they appear in the same order I added them. The reason this surprises me is that a Dictionary is supposed to be a HashTable internally, so I expected things to come out in ANY order (ordered...

What is C# analog of C++ std::pair?

I am interested what is C# analog of C++ std::pair? I have found System.Web.UI.Pair class, but wanted something template based. Thank you! ...

Array Vs. Linked List

I apologize--this question may be a bit open-ended but I think there are probably definite, quantifiable answers to it so I'll post it anyway. A person I know is trying to learn C++ and software development (+1 to him) and he asked me why someone would want to use a linked list in preference to an array. Coding a linked list is, no dou...

Adding durability to in-memory data structures

What are some of the popular techniques you can adopt to add durability to your in-memory data structures (ie) if the process crashes, you can preserve all previously executed operations on that data structure? If my data structure involves just a list of tuples, then I would just store them in a SQL DB and that would give me durabilit...

Is it possible to query a tree structure table in MySQL in a single query, to any depth?

I'm thinking the answer is no, but I'd love it it anybody had any insight into how to crawl a tree structure to any depth in SQL (MySQL), but with a single query More specifically, given a tree structured table (id, data, data, parent_id), and one row in the table, is it possible to get all descendants (child/grandchild/etc), or for tha...

Looking for the suffix tree implementation in C#?

I've implemented a basic search for a research project. I'm trying to make the search more efficient by building a suffix tree. I'm interested in a C# implementation of the Ukkonen algorith. I don't want to waste time rolling my own if such implementation exists. ...

Exceptions for flow of control

There is an interesting post over here about this, in relation to cross-application flow of control. Well, recently, I've come across an interesting problem. Generating the nth value in a potentially (practically) endless recursive sequence. This particular algorithm WILL be in atleast 10-15 stack references deep at the point that it s...

Updating an object within a Set

Hey, Let's say I have this type in my application: public class A { public int id; public B b; public boolean equals(Object another) { return this.id == ((A)another).id; } public int hashCode() { return 31 * id; //nice prime number } } and a Set<A> structure. Now, I have an object of type A and want to do the following: If...

Bitfields in C#

So, bitfields. Specifically, large bitfields. I understand how to manipulate individual values in a bitfield, but how would I go about doing this on a large set, such as say: uint[] bitfield = new uint[4] { 0x0080000, 0x00FA3020, 0x00C8000, 0x0FF00D0 }; The specific problem I'm having is doing left and right shifts that carry through ...

Hashtable implementation for Delphi 5

Do you know a good and free Hashtable imlementation for Delphi 5 ? I need to organize a huge amount of data in a hastable and I am bit worried about memory leak issues that I found in most available implementations on the web. Tks ...

Is there a master list of the Big-O notation for everything?

Is there a master list of the Big-O notation for everything? Data structures, algorithms, operations performed on each, average-case, worst-case, etc. ...

Referencing a javascript object literal array

How would you reference the models (Accord, CRV, Prius, etc) in this structure? Is this a bad structure to be able to extract the makes...then use a make to get the models...then use the model to get the options? var cars = [ { "makes" : "Honda", "models" : [ {'Accord' : ["2dr","4dr"]} , ...

Efficiently shrinking a two dimensional array in C#

What is an efficient way to shrink a two dimensional array to a smaller size in C#? For example: var bigArray = new object[100, 100]; var smallArray = new object[10, 10]; bigArray[0, 0] = 1; bigArray[0, 1] = 2; ... bigArray[99, 99] = 100000; startRowIndex = 0; startColumnIndex = 0; endRowIndex = 9; endColumnIndex = 9; smallArray = ...

Convert XML Data to Strong Flex Type

A project I'm working on will pull XML from a web-server and build a data store from it. The data will have certain core fields but needs to be extendable... for example I have a and later might want to have which adds extra fields. In the Flex app, I don't want the central data store to be working on XML objects or simply putting the...

How to store images in your filesystem

Currently, I've got images (max. 6MB) stored as BLOB in a InnoDB table. As the size of the data is growing, the nightly backup is growing slower and slower hindering normal performance. So, the binary data needs to go to the file system. (pointers to the files will be kept in the DB.) The data has a tree like relation: - main site -...