data-structures

How to name a struct that represents both a size and a position?

I have a structure named WaveSize to represent both an amount of samples or an amount of time, but I'm also using this structure to represent a position or an offset within a wave. While it's pretty common to represent both sizes and positions within a coordinate system with a Vector2d type, I'm unable to find a good name abstract enoug...

What other improvements in .NET's Dictionary vs. HashTable besides [un]boxing?

Trying to convince someone to switch from .NET 1.1 I saw people saying that one advantage of using the Dictionary class in post .NET 1.1 is performance increases due to not having to unbox/cast objects. Are there another improvements besides that? Or any other general advantages to moving away from .NET 1.1 ? ...

is it possible to add a list to a structure?

Is it possible to add a list to a struct? public struct test { public string x; list<string> y = new list<string>(); } something like that? ive been trying but im just not getting it ...

Union – useless anachronism or useful old school trick?

I recently came across a great data structures book,"Data Structures Using C" (c) 1991, at a local Library book sale for only $2. As the book's title implies, the book covers data structures using the C programming language. I got the book knowing it would be out-dated but would probably contain lots of advanced C topics that I wouldn't...

A data-structure for 1:1 mappings in python?

I have a problem which requires a reversable 1:1 mapping of keys to values. That means sometimes I want to find the value given a key, but at other times I want to find the key given the value. Both keys and values are guaranteed unique. x = D[y] y == D.inverse[x] The obvious solution is to simply invert the dictionary every time I...

Memory Efficient Methods To Find Unique Strings

I have a data set that looks like this: 000 100 200 300 010 020 030 001 002 003 001 101 201 301 011 021 031 000 002 003 002 102 202 302 012 022 032 001 000 003 003 103 203 303 013 023 033 001 002 000 010 110 210 310 000 020 030 011 012 013 020 120 220 320 010 000 030 021 022 023 030 130 230 330 010 020 000 031...

Automated field re-ordering in C structs to avoid padding

I've spent a few minutes manually re-ordering fields in a struct in order to reduce padding effects[1], which feels like a few minutes too much. My gut feeling says that my time could probably be better spent writing up a Perl script or whatnot to do this kind of optimization for me. My question is whether this too is redundant; is the...

Reading binary file defined by a struct

Hi, Could somebody point me in the right direction of how I could read a binary file that is defined by a C struct? It has a few #define inside of the struct, which makes me thing that it will complicate things. The structure looks something like this: (although its larger and more complicated than this) struct Format { unsigned lon...

B+ trees, choosing the order

I am studying B+ trees for the first time. I just want to know, on what basis should a developer choose the order of the B+ tree? Also, is there something like, B+ trees for the dummies tutorial? I desperately need it. ...

B- trees, B+ trees difference

In a B- tree you can store both keys and data in the internal/leaf nodes. But in a B+ tree you have to store the data in the leaf nodes only. Is there any advantage of doing the above in a B+ tree? Why not use B- trees instead of B+ trees everywhere? As intuitively they seem much faster. I mean why do you need to replicate the key(data) ...

How would I go about making an efficient key value store (e.g. memcache) / simple database?

For a few projects I'm working on I need a persistent key value store (something akin to memcache). It would ideally run as a server; it needs to be really efficient. I'm aware that memcachedb exists, but I'd like to have a go at writing it myself as there's going to be a lot of custom functionality that I'll need to include later on. I'...

Hill climbing and single-pair shortest path algorithms

I have a bit of a strange question. Can anyone tell me where to find information about, or give me a little bit of an introduction to using shortest path algorithms that use a hill climbing approach? I understand the basics of both, but I can't put the two together. Wikipedia has an interesting part about solving the Travelling Sales Per...

Data structure/algorithm for variable length record storage and lookup on disk withsearch only on primary keys

I am looking for an algorithm / data structure that works well for large block based devices (eg a mechanical hard drive) which is optimised for insert, get, update and delete where searches are always done using the id of the data and where the data fields for any ID have a variable length. The B-Tree seems to be a commonly quoted stru...

Why can I define structures and classes within a function in C++?

I just mistakenly did something like this in C++, and it works. Why can I do this? int main(int argc, char** argv) { struct MyStruct { int somevalue; }; MyStruct s; s.somevalue = 5; } Now after doing this, I kind of remembered reading about this trick someplace, a long time ago, as a kind of poor-man's funct...

Looking a data structure that is a Map but in which keys can be values, values can be keys

A Map maps from keys to values and provides quick access based on the knowledge of the key. Does there exist a data structure like Maps which supports both key to value and value to key access? Sometimes I may want to derefence the Map via the value, while other times by the key. ...

Stack or Not?

Lets say I have a Data Structure similar to Stack but in addition to usual Push/Pop it also has functions such as PushAt/PopAt both of which takes an integer as input and adds/returns the item at that particular location in data structure. Now Stack is suppose to be LIFO. Does this data structure qualify as "Stack"? ...

Hash tables using VLists

Phil Bagwell, in his 2002 paper on the VList data structure, indicates that you can use a VList to implement a persistent hash table. However, his explanation of how that worked didn't include much detail, and I don't understand it. Can anybody give me a more detailed explanation, or even examples? Further, it appears to me from what I ...

getting a substruct out of a big struct in C

I'm having a very big struct in an existing program. This struct includes a great number of bitfields. I wish to save a part of it (say, 10 fields out of 150). An example code I would use to save the subclass is: typedef struct {int a;int b;char c} bigstruct; typedef struct {int a;char c;} smallstruct; void substruct(smallstruct *s,bi...

Documentation on Apple Mail's .emlx data structure(s) (for conversion purposes)?

This appears to be a rare gem: where to find documentation on the structure of Apple Mail's .emlx files (and their partial variants, and the meaning of the directory structures). The docs do not appear to exist on Apple's site, nor can I find any reasonable mention of it via Google. The point of this is the creation of a bash/ruby/pyth...

What are Self-Adjusting Data Structures?

What do you mean by "self-adjusting" data structures? How are they different from other data structures? Where are they used? Edit: Why would adjust a data structure if operations other than insert and delete are performed? ...