data-structures

Are empty Binary Search Trees valid?

I have two questions regarding binary search trees, both about empty trees. Is an empty tree (null) valid? Is a root node without children valid? ...

C# Stack with deletable elements

I need a stack structure that also allows the for the deleting of elements. I can't find anything like this in the .Net framework. Which structure provides the best basis for me to implement this? ...

Java: Converting arrays of arrays to collections of collections and vice versa.

Please suggest some elegant way to convert arrays of arrays to collections of collections and vice versa in Java. I suppose there's no convenience methods in the Java API, right? public static <T> T[][] nestedCollectionsToNestedArrays( Collection<? extends Collection<T>> source){ // ... ? } public static <T> Collection<Collecti...

How do I make and use a Queue in Objective-C?

I want to use a queue data structure in my Objective-C program. In C++ I'd use the STL queue. What is the equivalent data structure in Objective-C? How do I push/pop items? ...

JAXB: How should I marshal complex nested data structures?

Hello! I have several complex data structures like Map< A, Set< B > > Set< Map< A, B > > Set< Map< A, Set< B > > > Map< A, Map< B, Set< C > > > and so on (more complex data structures) Note: In my case it doesn't really matter if I use Set or List. Now I know that JAXB let me define XmlAdapter's, that's fine, but I don't want to def...

A way to reverse queue using only two temporary queues and nothing more?

Is there a way to reverse items' order in queue using only two temporary queues (and no other variables, such as counters)? Only standard queue operation are available: ENQUEUE(e), DEQUEUE(), EMPTY()? Solutions in any language or pseudocode are welcome. ...

How to implement a Map with multiple keys?

Hello! I need a data structure which behaves like a Map, but uses multiple (differently-typed) keys to access its values. (Let's don't be too general, let's say two keys) Keys are guaranteed to be unique. Something like: MyMap<K1,K2,V> ... With methods like: getByKey1(K1 key)... getByKey2(K2 key)... containsKey1(K1 key)... contai...

Does the amount of code make a data structure larger?

I have an arraylist of items that only have maybe ten variables in them. But the items have a good bit of code, and I'd like to add more. I'm curious how this will effect the size of my structure. My intuition tells me each one has a stack, but with arguments getting passed around and stuff I've probably not considered I'm unsure. So rou...

What is the data structure of the Inode number like?

I am flabbergasted by the definition of the inode number: An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An inode stores basic information about a regular file, directory, or other file system object. Source So there must be a logical order in every inode number. Can you conclude somet...

What does the following C++ struct syntax mean..

If I have a C++ struct, defining a 64bit data word such as.. struct SMyDataWord { int Name : 40; int Colour : 24; }; What does the : 40 syntax mean... does it mean that the first 40 bits are reserved for the Name and the remaining 24 bits for the Colour? This is how it appears to be being used, but I've not come across it be...

How do you implement a circular buffer in C?

I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don't think there will be resource contention issues since, although it's in a multi-tasking embedded environment, it's a co-operative one so the tasks t...

Why is inserting at the end of a dynamic array O(1) while inserting in the middle is O(n)?

Accordingly to the Wikipedia article on dynamic arrays, inserting/deleting at the end of the array is O(1) while inserting/deleting from the middle is O(n). Why exactly is that? Also - if I have a dynamic array with 5 elements and I insert a new element at position 6 the operation is O(n) whereas if I use the function to append to the ...

What are the advantages of Blocking Queue in Java?

I am working on a project that uses a queue that keeps information about the messages that to be sent to remote hosts. In that case one thread is responsible to put the information into the queue and another thread is responsible for get the pop the information from the queue and send. In that case the 2nd thread needs to check the queue...

How to create a binary tree

I did'nt mean binary search tree. for example, if I insert values 1,2,3,4,5 in to a binary search tree the inorder traversal will give 1,2,3,4,5 as output. but if I insert the same values in to a binary tree, the inorder traversal should give 4,2,5,1,3 as output. Binary tree can be created using dynamic arrays in which for each eleme...

three item HashMap without internal iteration

What is the best way to implement a three item hashMap? For example, I would like to use a regular String key , but have it map to two different objects. The idea is like having a list of lists, except that the first item is a key. I am trying to avoid iterating through the list ( so the behavior is like a hashmap ). Would you agree the...

Best approach to holding large editable documents in memory

I need to hold a representation of a document in memory, and am looking for the most efficient way to do this. Assumptions The documents can be pretty large, up to 100MB. More often than not the document will remain unchanged - (i.e. I don't want to do unnecessary up front processing). Changes will typically be quite close to each oth...

XML to C struct and C struct to XML

I like to do my server side programming in C, but need to inter-operate with some XML. What I need to write is some function that, given a C structure, or nested structure, and another structure (or nested structures) that describes the elements in the C structure, spits it out as XML. And another function that reads the XML, verifies ...

Memory Based Data Server for local IPC

I am going to be running an app(s) that require about 200MB of market data each time it runs. This is trivial amount of data to store in memory these days, so for speed thats what i want to do. Over the course of a days session I will probably run, re-run, re-write and re-run etc etc one or more applications over and over. SO, the ques...

Are there strongly-typed collections in Objective-C?

I'm new to Mac/iPhone programming and Objective-C. In C# and Java we have "generics", collection classes whose members can only be of the type declared. For example, in C# Dictionary<int, MyCustomObject> can only contain keys that are integers and values that are of type MyCustomObject. Does a similar mechanism exist in Objective-C...

Efficient modelling of an MruList in C# or Java

How would you implement a capacity-limited, generic MruList in C# or Java? I want to have a class that represents a most-recently-used cache or list (= MruList). It should be generic, and limited to a capacity (count) specified at instantiation. I'd like the interface to be something like: public interface IMruList<T> { public...