data-structures

B+ tree implementation, * * vs *

I am writing a B+ tree for a variety of reasons and I am come here to ask a question about implementation of its nodes. My nodes currently look like: struct BPlusNode { public: //holds the list of keys keyType **keys; //stores the number of slots used size_t size; //holds the array of pointers to lower nodes NULL if ...

Inverse Dict in Python

I am trying to create a new dict using a list of values of an existing dict as individual keys. So for example: dict1 = dict({'a':[1,2,3], 'b':[1,2,3,4], 'c':[1,2]}) and I would like to obtain: dict2 = dict({1:['a','b','c'], 2:['a','b','c'], 3:['a','b'], 4:['b']}) So far, I've not been able to do this in a very clean way. Any sugg...

Best way to create large hashmap at compile time (C++)?

In my application, I need a hash map mapping strings to a large number of static objects. The mappings remain fixed for the duration of the application. Is there an easy way to pre-generate the mappings at compile time rather than building it element-by-element when the application starts? ...

Deterministic handle allocation algorithm

I'm trying to find an efficient deterministic way of allocating a 32-bit handle in such a way that it will operate indefinitely. A simple incrementing counter will not work because it will eventually loop around. Extending to 64-bits isn't possible because the values will be used in a network protocol which is expecting a 32-bit value. ...

MATLAB linked list

What are some possible ways to implement a linked list in MATLAB? Note: I am asking this question for pedagogical value, not practical value. I realize that if you're actually rolling your own linked list in MATLAB, you're probably doing something wrong. However, I'm a TA for a class that is MATLAB-intensive this semester, and my goa...

Which is the fastest search technique/method? (In context of file searching)

I don't know what they use in normal windows searching.But there is a technique in which you use indexing of files at once and then use the index later for faster searching.(e.g. Windows search 4.0) Is there any other way for faster searching than this? Can you elaborate from implementation point of view? (Assuming that I may need to im...

typedef'ing an array vs. using a struct in C++

Found an interesting use of a typedef that I really didn't see the need for. typedef int Color[3]; So then the use would be: Color pants; pants[0] = 0; etc. Using the typedef through ptrs was creating strange looking code that wasn't clear. Why not just use a struct? struct Color { int r; int g; int b; }; Color pants; pants.r = ...

Python implementation question

Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations). I think an equivalent question would be that y...

How expensive are Python dictionaries to handle?

As the title states, how expensive are Python dictionaries to handle? Creation, insertion, updating, deletion, all of it. Asymptotic time complexities are interesting themselves, but also how they compare to e.g. tuples or normal lists. ...

linkedlist which links to itself?

Hi All, Is there a name for a linked list type structure where the head and tail nodes link to each other? In such a list you can obviously iterate through it forever as it double backs on itself. Was just wondering. ...

Why is vector array doubled?

Why does the classic implementation of Vector (ArrayList for Java people) double its internal array size on each expansion instead of tripling or quadrupling it? ...

Symmetrically adressable matrix

I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to fill a list of lists wi...

LinkedBlockingQueue vs ConcurrentLinkedQueue

My question relates to this question asked earlier. In situations where I am using a queue for communication between producer and consumer threads would people generally recommend using LinkedBlockingQueue or ConcurrentLinkedQueue? What are the advantages / disadvantages of using one over the other? The main difference I can see from ...

Search For String Permutations In String Set

The title of this is kind of awkward; I wasn't really sure how to sum this up. I know how I can do this, I'm just not sure how to do it efficiently. Here's my problem: I have a string as input. Let's say: foo bar And I have a very large set of strings (tens of thousands). Let's say: foo, baz, bar, blah, foo bar, foo baz I...

C++ Class or Struct compatiblity with C struct

Is it possible to write a C++ class or struct that is fully compatible with C struct. From compatibility I mean size of the object and memory locations of the variables. I know that its evil to use *(point*)&pnt or even (float*)&pnt (on a different case where variables are floats) but consider that its really required for the performance...

Problem with clearing a List<T>

I don't know why I have an IndexOutOfRangeException when I am clearing a System.Collections.Generic.List<T>. Does this make sense? List<MyObject> listOfMyObject = new List<MyObject>(); listOfMyObject.Clear(); ...

How to use two numbers as a Map key

I have two numbers and I want to use them together as a key in a Map. Currently, I'm concatenating their string representations. For example, suppose the key numbers are 4 and 12. I use: String key = 4 + "," + 12; The map is declared as Map<String, Object>. I think this is so bad! I like to use something other than a String as the ke...

Is there any practical usage of Doubly Linked List, Queues and Stacks?

I've been coding for quite sometime now. And my work pertains to solving real-world business scenarios. However, I have not really come across any practical usage of some of the data structures like the Linked List, Queues and Stacks etc. Not even at the business framework level. Of course, there is the ubiquitous HashTable, ArrayList a...

Explaining persistent data structures in simple terms

I'm working on a library for Python that implements some persistent data structures (mainly as a learning exercise). However, I'm beginning to learn that explaining persistent data structures to people unfamiliar with them can be difficult. Can someone help me think of an easy (or at least the least complicated) way to describe persist...

access data from another content element in templavoila data structure

I defined a page content element which has a background picture. It's a simple mapping on an attribtue with a wrap. Everything is working fine and the typoscript part of the data structure looks like this: 10 = IMG_RESOURCE 10.file.import = uploads/tx_templavoila/ 10.file.import.current = 1 10.file.import.listNum = 0 10.stdWrap.wrap = b...