data-structures

Space-Efficient Data Structure for Storing a Word List?

Is there anything better than a Trie for this situation? Storing a list of ~100k English words Needs to use minimal memory Lookups need to be reasonable, but don't have to be lightning fast I'm working with Java, so my first attempt was to just use a Set<String>. However, I'm targeting a mobile device and already running low on memor...

In red-black trees is top-down deletion faster and more space efficient than bottom-up deletion?

Per this page http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx "Top-down deletion" is an implementation of a red-black tree node removal that pro-actively balances a tree by pushing a red node down through the tree so that the leaf node which is being removed is guaranteed to be red. Since the leaf node is gua...

Good Data Structures text book

Which is the best book on Data structures to refer to? ...

JavaScript Hashmap Equivalent

As made clear in update 3 on this answer, this notation: var hash = {}; hash[X] does not actually hash the object X; it actually just converts X to a string (via .toString() if it's an object, or some other built-in conversions for various primitive types) and then looks that string up, without hashing it, in "hash". Object equality i...

SQL database problems with addressbook table design

Hello! I am writing a addressbook module for my software right now. I have the database set up so far that it supports a very flexible address-book configuration. I can create n-entries for every type I want. Type means here data like 'email', 'address', 'telephone' etc. I have a table named 'contact_profiles'. This only has two colu...

Convert C++ Header Files To Python

I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated. ...

How can I execute a given function on every element of a complicated data structure in Perl?

I want to decode all the HTML entities in a complicated data structure. Basically I'm looking for a "super map()" function. Here's what I have so far: sub _html_decode { my $self = shift; my $ref = shift; if (ref($ref) eq "HASH") { $self->_html_decode_hash($ref) } if (ref($ref) eq "ARRAY") { $self->_...

Are data structures an appropriate place for shared_ptr?

I'm in the process of implementing a binary tree in C++. Traditionally, I'd have a pointer to left and a pointer to right, but manual memory management typically ends in tears. Which leads me to my question... Are data structures an appropriate place to use shared_ptr? ...

C# Dictionary Memory Management

I have a Dictionary<string,int> that has the potential to contain upwards of 10+ million unique keys. I am trying to reduce the amount of memory that this takes, while still maintaining the functionality of the dictionary. I had the idea of storing a hash of the string as a long instead, this decreases the apps memory usage to an accept...

What is the Zipper data structure and should I be using it?

The question is simple: I cannot understand the Zipper data structure. My question is related to its uses with a Tree. I want to understand how can I change the tree node using zipper. And how not to copy the whole tree (or the most part of it). Please, clarify if I'm wrong with zipper. Maybe it cannot help with the tree update? Or, m...

efficient algorithm to test _which_ sets a particular number belongs to

If I have a large set of continuous ranges ( e.g. [0..5], [10..20], [7..13],[-1..37] ) and can arrange those sets into any data-structure I like, what's the most efficient way to test which sets a particular test_number belongs to? I've thought about storing the sets in a balanced binary tree based on the low number of a set ( and each ...

Best practice to fill an object hierarchy from a flat database resultset?

This is a frequently recurring problem of generating a tree from a flat list. I have caught myself relying on the two-level method described below. I would appreciate anyone suggesting a better approach that could be easily extended to multiple levels. Description: Resultset is flat and contains a reference to a parentId Root items w...

Data structure for relationships

Hi All -- I am converting a VB6 to C# and I want to make my data structure that holds values and relationships more efficient. In VB I have a collection of values and another collection of relationships between those values with priorities for those relationships. I also have an algorithm that when a set of values is passed to it all re...

Advanced data structures in practice

In the 10 years I've been programming, I can count the number of data structures I've used on one hand: arrays, linked lists (I'm lumping stacks and queues in with this), and dictionaries. This isn't really surprising given that nearly all of the applications I've written fall into the forms-over-data / CRUD category. I've never needed ...

Weekly Schedules - How can you store this in a database?

Currently, I'm working on a project to manage maintenance windows on a database of servers, etc. Basically, I only need to be accurate down to the hour, but allow for them to be set to allow, or disallow, for each day of the week. I've had a few ideas on how to do this, but since I work by myself, I'm not wanting to commit to anything w...

Queues in the Linux Kernel

I've been searching for information for a common kernel implementation of queues, that is, first-in-first-out data structures. I thought there may be one since it's likely something that's common to use, and there's a standard for linked lists (in the form of the list_head structure). Is there some standard queue implementation I can't...

Producing documentation for Python classes

I'm about to start a project where I will be the only one doing actual code and two less experienced programmers (scary to think of myself as experienced!) will be watching and making suggestions on the program in general. Is there a good (free) system that I can use to provide documentation for classes and functions based on the code I...

How can I read Perl data structures from Python?

I've often seen people use Perl data structures in lieu of configuration files; i.e. a lone file containing only: %config = ( 'color' => 'red', 'numbers' => [5, 8], qr/^spam/ => 'eggs' ); What's the best way to convert the contents of these files into Python-equivalent data structures, using pure Python? For the time being...

How can I create cells or grids in C++ for a randomized maze?

I'm trying to create a randomized maze in C++, but I can't start because I don't know how to create grids or cells. How could I create it? And I also want to create it using ASCII characters. how can i store it in array? (can any one give a sample code and some explanation so i can understand it better) Another question: What data stuct...

What is a good data structure for cascading objects?

I have wondered what type of data structures and design patterns are used when implementing something like CSS where you can specify formatting or some other property at different levels of granularity. One specific example that I am working on at the moment relates to internationalization of an application. First of all English is the...