data-structures

Objects which send themselves - a good idea?

Where do you draw the line when moving functions which operate on data into the class which contains that data? For example, imagine you have a simple class which stores a description of the weather, with variables for temperature, humidity, wind speed and direction, and the time at which the measurement was taken. Now imagine you have...

Data format that looks like JSON, but isn't. Can you help identify it?

I have no friggin' clue what this data format is called. Do you recognize it? http://pastebin.me/ced13687cf12fb85b334a5960a4cf985 It's JSON-esque, but obviously not JSON. We can thank Google for blessing us with this little enigma. ...

Time Aware Social Graph DS/Queries

Classic social networks can be represented as a graph/matrix. With a graph/matrix one can easily compute shortest path between 2 participants reachability from A -> B general statistics (reciprocity, avg connectivity, etc) etc Is there an ideal data structure (or a modification to graph/matrix) that enables easy computation of the ...

Java collections maintaining insertion order

Why do some collection data structures not maintain the order of insertion? What is the special thing achieved compared to maintaining order of insertion? Do we gain something if we don't maintain the order? ...

Python: Should I put my data in lists or object attributes?

I am looking for an appropriate data structure in Python for processing variably structured forms. By variably structured forms I mean that the number of form fields and the types of the form's contents are not known in advance. They are defined by the user who populates the forms with his input. What are the pros and cons of putting da...

Confusion about linear probe method based Open Addressing in hashtables?

Suppose array index according to hashing function for string "temp" is 155 and location 155 is pre-occupied then location 156 is tried. Suppose location 156 is available, so this entry is saved in location 156 instead of 155. Later I find another string "another_temp", which maps to location 156. Again this is saved in next available loc...

C++ thread safe doubly linked list

I need the above data structure for an application I'm writing. I wondered if there is a library that already implements it or if I have to write it myself? I don't really want to reinvent the wheel if it is not necessary. I need this structure to be able to add and remove items using multiple threads without having to lock up the who...

How VIM Autocomplete Work

I was going over VIM shortcuts & found the CTRL+p which acts as an autocomplete in UNIX (you know what I am saying, a dropdown list of the possible words to use, sorted by frequency of usage). It seems to detect even the most immediately typed words. How does this work in VIM? I am specifically interested in the data structures that are ...

c# ordered combinations algorithm

Hi, I'm trying to develop a c# application that will generate a list of all possible permutations, within a limit, and cost. For example, I have a list of 80 jobs. Each job has a value (1-5) (typically 3) and each engineer has a limit of how much they can do, typically a value of 20. At the moment I've started by producing a list of ...

sending a struct to a function, previously defined with a pointer

Edit: Forget it. it was another part of the code (actually the problem was a secondary element. another pointer but not allocated with malloc, just declared, so i think the memory was allocated in another place). the example now can compile. thanks guys. im sorry for my typos but english isnt my native language(isnt a good escuse but i...

What is the reason behind this huge Performance difference in .Net 4

I was just doing some research on RedBlack Tree. I knew that SortedSet class in .Net 4.0 uses RedBlack tree. So I took that part out as is using Reflector and created a RedBlackTree class. Now I am running some perf test on this RedBlackTree and SortedSet inserting 40000 sequential integral values (starting from 0 to 39999), I am astonis...

How do I do this in ASP.net?

I want to implement a shopping basket. I created a shopping basket class, and included all the functions inside it that basket will need. It works OK, but on every content page I need the lines: Basket myBasket = new Basket(); myBasket.drawBasket(); Is there anyway to get that code to execute on every page without having to manually...

Generating potential schedules for college students.

Hello, Here is my problem: I am designing an application that will allow students to select the classes they want to take for the semester and create potential schedule layouts for them. Each class typically has several possible sections that occur at different times. So I am looking for a good data structure to use in order to develo...

C data structures

Is there a C data structure equatable to the following python structure? data = {'X': 1, 'Y': 2} Basically I want a structure where I can give it an pre-defined string and have it come out with an integer. ...

Better data structure for multiple checks for a variable than if statements?

So, I have this block of code, and yes it looks ugly. Is there a better a data structure I can use to compare row.add,row.modify,row.delete and row.query with "Y" and call the get_role function? Note this block of code runs in a loop, hence the 'row'. if row.add == "y" role_ids << get_role("c") end if row.modify == ...

Substring algorithm suggestion

I have a large set (100k) of short strings (not more than 100 chars) and I need to quickly find all those who have a certain substring. This will be used as a search box where the user starts typing and the system immediately gives "suggestions" (the strings that have as a substring the text that the user typed). Something similar to th...

On what platforms will this crash, and how can I improve it?

I've written the rudiments of a class for creating dynamic structures in C++. Dynamic structure members are stored contiguously with (as far as my tests indicate) the same padding that the compiler would insert in the equivalent static structure. Dynamic structures can thus be implicitly converted to static structures for interoperabilit...

Are there any performance penalties when using nested structures?

Are there any performance penalties when I use multiple nested structures/classes (kinda like using muti dimension heap arrays) or is it just an organizational feature of the language to make it easier to keep track of data and the compiler doesn't actually see any difference? Thanks ...

Writing an interpreter, need help representing this data

Hello, I am writing a small interpreter to show an example of Backus-Naur form and i would like to ask for help representing some data. <statement> : <assignment> | HALT | PRINT(<variable>) <assignment> : <variable> = <expression> <expression> : <term> | <term><operator><expression> <term> : <number> | <variable> <variable> : x | y | z ...

Arraylist in C.

HELLO WORLD, GUYS!!! I am currently writing a program to implement an arraylist (or dynamic array) in C. Hmm... I think I have 70 - 80% done with it, however, I found a serious problem with my codes when testing them on a couple of machines. Briefly, I inserted a group of strings( char* ) into my arraylist, and tried to get and display...