data-structures

Is it possible to use a string variable to reference an element in Javascript?

Here's the quick version of the code as it stands right now: function foo(attributeName, someJSObj, key, newValue) { someJSObj[key].attributeName = newValue; } Obviously this doesn't work, since it just creates a new element called attributeName. Is there an easy way to dereference the attributeName into the string that represent...

Accessing any structs members at run-time.

Is it possible to get access to an individual member of a struct or class without knowing the names of its member variables? I would like to do an "offsetof(struct, tyname)" without having the struct name or member variable name hard coded amoungst other things. thanks. ...

Are there any implementations of multiset for .Net?

I'm looking for a .Net implementation of a multiset. Can anyone recommend a good one? (A multiset, or bag, is a set that can have duplicate values, and on which you can do set operations: intersection, difference, etc. A shopping cart for instance could be thought of as a multiset because you can have multiple occurrences of the same pr...

How to find nth element from the end of a singly linked list?

The following function is trying to find the nth to last element of a singly linked list. For example: If the elements are 8->10->5->7->2->1->5->4->10->10 then the result is 7th to last node is 7. Can anybody help me on how this code is working or is there a better and simpler approach? LinkedListNode nthToLast(LinkedListNode head,...

DataGridView bound to a Dictionary and updated with a thread

I have a Dictionary binded to DataGridView by using following sample code. http://stackoverflow.com/questions/854953/datagridview-bound-to-a-dictionary Please see the above question first The diffrence is that i am updating dictionary from a thread. (Event handler of another class). My Event handler is as below static void f_PriceC...

Any simple approaches for managing customer data change requests for global reference files?

For the first time, I am developing in an environment in which there is a central repository for a number of different industry standard reference data tables and many different customers who need to select records from these industry standard reference data tables to fill in foreign key information for their customer specific records. ...

Reimplementing data structures in the real world

The topic of algorithms class today was reimplementing data structures, specifically ArrayList in Java. The fact that you can customize a structure for in various ways definitely got me interested, particularly with variations of add() & iterator.remove() methods. But is reimplementing and customizing a data structure something that is...

AVL tree in C language

Hey all; i am currently doing a project that requires the use of AVL trees , the insert function i wrote for the avl does not seem to be working , it works for 3 or 4 nodes at maximum ; i would really appreciate your help The attempt is below Tree insert(Tree t,char name[80],int num) { if(t==NULL) { t = (Tree)malloc(sizeof(stru...

Effects of changing a node in a binary tree

Suppose I want to change the orange node in the following tree. So, the only other change I'll need to make is in the left pointer of the green node. The blue node will remain the same. Am I wrong somewhere? Because according to this article (that explains zippers), even the blue node needs to be changed. Similarly, in this picture...

Storing a bucket of numbers in an efficient data structure

I have a buckets of numbers e.g. - 1 to 4, 5 to 15, 16 to 21, 22 to 34,.... I have roughly 600,000 such buckets. The range of numbers that fall in each of the bucket varies. I need to store these buckets in a suitable data structure so that the lookups for a number is as fast as possible. So my question is what is the suitable data stru...

Access Violation Using memcpy or Assignment to an Array in a Struct

Update 2: Well I’ve refactored the work-around that I have into a separate function. This way, while it’s still not ideal (especially since I have to free outside the function the memory that is allocated inside the function), it does afford the ability to use it a little more generally. I’m still hoping for a more optimal and elegant s...

C++ priority queue structure used ?

While searching for some functions in C++ STL documentation I read that push and pop for priority queues needs constant time. http://www.cplusplus.com/reference/stl/priority_queue/push/ "Constant (in the priority_queue). Although notice that push_heap operates in logarithmic time." My question is what kind of data structure is used...

How would be data stored at database in case of social networking site?

In social networking site, a person has friends/followers. There is a chain of relation. How would be data stored at database in this scenario? This is a very huge information, still result of a query comes back very fast on these sites. Is it possible that someone explain the relations between various entities? What does make the searc...

What would be the datastructure in following scenario? (Stack with maximum)

Please note that there is no limitation of memory. I need to insert int from 1 to 1000. I can do the each of the following operations in constant order of time: push():adds to the top pop():removes the top element getMax(): returns the max element Please suggest me appropriate datastructure. ...

How to simulate tuples and sets in C#?

I want to use some features of python like as Tuples and Sets in c#. should I implement them? or there are already implemented? could anybody knows a library of dynamic data structures for .net languages? ...

Fast data structure for small sets

I'm in need for a data structure that can handle small sets (10-20 strings, at most 50, of varying length) very fast. False positives is ok, but false negatives are not. The last requirement makes bloom filters seem like a good fit, but I'm not sure about their speed, any other recommendations? Edit: The set only needs to support ins...

Binary Search Tree Implementation

I've searched the forum, and tried to implement the code in the threads I found. But I've been working on this real simple program since about 10am, and can't solve the seg. faults for the life of me. Any ideas on what I'm doing wrong would be greatly appreciated. BST.h (All the implementation problems should be in here, and this has ...

How do you make an in-place construction of a struct casted to array compile in Visual C++ 2008?

I'm working with quite a big codebase which compiles fine in linux but vc++ 2008 spits errors. The problem code goes like this: Declaration: typedef float vec_t; typedef vec_t vec2_t[2]; The codebase is littered with in-place construction like this one: (vec2_t){0, divs} Or more complex: (vec2_t){ 1/(float)Vid_GetScreenW(), 1/(float)...

Suggest a good method with least lookup time complexity

I have a structure which has 3 identifier fields and one value field. I have a list of these objects. To give an analogy, the identifier fields are like the primary keys to the object. These 3 fields uniquely identify an object. Class { int a1; int a2; int a3; int value; }; I would be having a list of say 1000 object of th...

What is better, a STL list or a STL Map for 20 entries, considering order of insertion is as important as the search speed.

I have the following scenario.The implementation is required for a real time application. 1)I need to store at max 20 entries in a container(STL Map, STL List etc). 2)If a new entry comes and 20 entries are already present i have to overwrite the oldest entry with the new entry. Considering point 2, i feel if the container is full (Max...