data-structures

Opposite of Bloom filter?

Hi, I'm trying to optimize a piece of software which is basically running millions of tests. These tests are generated in such a way that there can be some repetitions. Of course, I don't want to spend time running tests which I already ran if I can avoid it efficiently. So, I'm thinking about using a Bloom filter to store the tests wh...

What is a good way to determine dates in a date range?

What is a good Perl module (or good approach) that returns all the valid calendar dates between a start date and an end date? For example, if I have 1/29/2009 as a start date and 2/3/2009 as an end date then I would like it to return an array of 1/30/2009, 1/31/2009, 2/1/2009, and 2/2/2009. There must be a good Perl module that already...

Write-Once + Read-Numerous Map in Java?

Hi guys, I have a requirement that a Map will be constructed with up to 50~200 entries (it could be more, let's call it not-too-little anyway). The writing is only done once and the reading (using Map.get("keyName")) can go more than 20 per request (it's a webapp). I'm going for Hashmap currently as it (I suppose) gives me the most opt...

Efficient persistent storage for simple id to table of values map for java

I need to store some data that follows the simple pattern of mapping an "id" to a full table (with multiple rows) of several columns (i.e. some integer values [u, v, w]). The size of one of these tables would be a couple of KB. Basically what I need is to store a persistent cache of some intermediary results. This could quite easily be ...

Python: Incrementally marshal / pickle an object?

I have a large object I'd like to serialize to disk. I'm finding marshal works quite well and is nice and fast. Right now I'm creating my large object then calling marshal.dump . I'd like to avoid holding the large object in memory if possible - I'd like to dump it incrementally as I build it. Is that possible? The object is fairly si...

C# Struct usage tips?

I like using structs a lot. So after reading this article, are there any other concerns I should have against using them all the time? See Also: When should I use a struct instead of a class? When to use struct in C#? ...

Exposing array-like data structure using properties

Its typical to expose internal data structures as properties to your business class. But when we have to expose array-like structures (like List<Rule> rules) we might encounter a problem of wrong usage (as in Option 1). Its suggested to expose clone of such data structures as properties, so that internal structure does not get disturbe...

What's the difference between data and code?

To take an example, consider a set of discounts available to a supermarket shopper. We could define these rules as data in some standard fashion (lists of qualifying items, applicable dates, coupon codes) and write generic code to handle these. Or, we could write each as a chunk of code, which checks for the appropriate things given th...

What is the best data structure for this in-memory lookup table?

I need to store a lookup table as an instance member in one of my classes. The table will be initialized when the object is constructed. Each "row" will have 3 "columns": StringKey (e.g., "car") EnumKey (e.g., LookupKeys.Car) Value (e.g, "Ths is a car.") I want to pick the data structure that will yield the best performance for doin...

B-tree faster than AVL or RedBlack-Tree?

I know that performance never is black and white, often one implementation is faster in case X and slower in case Y, etc. but in general - are B-trees faster then AVL or RedBlack-Trees? They are considerably more complex to implement then AVL trees (and maybe even RedBlack-trees?), but are they faster (does their complexity pay off) ? E...

What is best data structure suitable to implement editor like notepad?

Which data structure/s is used in implementation of editors like notepad. This data structure should be extensible, and should support various features like edition, deletion, scrolling, selection of range of text etc? ...

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

Can I make an NSMutableArray where all the elements are of type SomeClass? ...

Any library for generic datatypes in C?

I am trying to write a 2d game engine in C (no c++). What are some good libraries that have generic data types I may need - for example queues, trees, maps, lists, and so on? ...

Howto Create Map of Vector From Sorted Data

Dear all, I have the following data as input (sorted by first column): foo 1 2 foo 3 3 bar 10 11 I want to create a Map of Vector with first column as key of the map such that we have: foo = {1,2,3,3} bar = {10,11} But why my code below doesn't work as expected? #include <vector> #include <map> #include <iostream> ...

(More) Efficient locking when rotating nodes in threaded binary tree

So, I've come up with this scheme for locking nodes when rotating in a binary tree that several threads have both read and write access to at the same time, which involves locking four nodes per rotation, which seems to be an awfully lot? I figured some one way smarter then me had come up with a way to reduce the locking needed, but goog...

The right data structure to use for an Excel clone

Let say I'm working on an Excel clone in C#. My grid is represented as follows: private struct CellValue { private int column; private int row; private string text; } private List<CellValue> cellValues = new List<CellValue>(); Each time user add a text, I just package it as CellValue and add it into cellValues. Given a Cel...

Is there a Java Collection (or similar) that behaves like an auto-id SQL table?

Note that I'm not actually doing anything with a database here, so ORM tools are probably not what I'm looking for. I want to have some containers that each hold a number of objects, with all objects in one container being of the same class. The container should show some of the behaviour of a database table, namely: allow one of the ...

Algorithms and data structures that are not mainstream?

There are a subset of algorithms and data structures that are very common, well-studied and very helpful. Examples of these are Topological sort, quicksort, depth-first search; on the other hand, dictionaries, trees, linked-lists and to a lesser extent red-black trees, and tries, are examples of the latter. However, there are other alg...

I am looking for a content addressing data structure

I'm trying to design a data structure that allows efficient extraction of entries from a part of their content. Let's say I am looking for an entry that matches this: [ x 2 3 x x ] If [ 0 2 3 4 5 ] or [ 3 2 3 7 8 ] are in my data structure, they should be returned by my find function. I wrote such a data structure where I compare the...

What background is needed for reading "Purely Functional Data Structures" ?

I have just finished reading Little Schemer.. Now I am planning on reading Purely Functional Data Structures.. but the notations in the book looks very complicated.. are there easier alternative to this book that talk about data structure in functional languages.. if not then what do I need to read before I can start on this book... Th...