data-structures

Performance hit incurred using NSMutableDictionary vs. NSMutableArray>

I am considering using an NSMutableDictionary in place of my current NSMutableArray. This is primarily for KVC/KVO reasons. The collection will undergo heavy mutation within the inner loop of my drawing method. Can I expect to incur a significant performance hit if I go ahead with this replacement? Cheers, Doug ...

Java implementation for Min-Max Heap?

Do you know of a popular library (apache collections, google collections, etc...) which has a reliable Java implementation for a Min-Max heap? I.e. a heap which allows to peek at its minimum and maximum value in O(1) and to remove at O(logn). I did a quick search and couldn't find one. Anyone know better? ...

Replace [StructLayout] with something that doesn't use System.Runtime.InteropServices?

I have no experience with low level programing and I need this piece of code to not use [StructLayout(LayoutKind.Explicit)]. My site runs on a shared host and in medium trust. So it won't run if this code is in there. Update: I'm using this inside a Octree to Quantize a png file. Does anyone know a work around? Update New question her...

Opinion Poll on Unnamed Structs

Having a bit of internal debate in my group about the use of unnamed structs\unions in our C++ code. I'd like to get feedback from the community of what you think. Should they be used at all? When is it valuable? What are the pitfalls? etc. Example: union SFlags { struct { unsigned int A : 1; unsigned int B...

Best Data Structure for Genetic Algorithm in C++ ?

Hello, i need to implement a genetic algorithm customized for my problem (college project), and the first version had it coded as an matrix of short ( bits per chromosome x size of population). That was a bad design, since i am declaring a short but only using the "0" and "1" values... but it was just a prototype and it worked as intend...

Is there a Queue/FIFO data structure for the iPhone?

Before I roll my own Queue using NSMutableArray, I'd like to know if there is something more standard available. I don't see anything in the Apple docs, but I'll be surprised if there is not a Queue implementation from somewhere that folks are using. Java spoils me! ...

Beans, methods, access and change? What is the recommened practice for handling them (i.e. in ColdFusion)?

I am new to programming (6 weeks now). i am reading a lot of books, sites and blogs right now and i learn something new every day. Right now i am using coldfusion (job). I have read many of the oop and cf related articles on the web and i am planning to get into mxunit next and after that to look at some frameworks. One thing bothers m...

[Coding Exercise] What are some ways to map & normalize related data?

Let's say you need to funnel random, related data given to you into more succinct categories. Example - You're given the following data. NOTE - There could be any number of other related, columnar data: Customer Product Category ========== ========= ================================= Customer A Product A ...

Implementing -hash / -isEqual: / -isEqualTo...: for Objective-C collections

Note: The following SO questions are related, but neither they nor the linked resources seem to fully answer my questions, particularly in relation to implementing equality tests for collections of objects. Best practices for overriding -isEqual: and -hash Techniques for implementing -hash on mutable Cocoa objects Background NSObj...

C#: How would you store arbitrary objects in an SQL Server?

Lets say you have various objects of arbitrary type that you would like to store in a key+value type of table. Key could for example be an int, string or guid. What would the value be? String, Binary or something else? And how would you store and load the objects? I would think some sort of serialization, but what kind? I have one so...

C#: What style of data containers are preferred in general?

When creating a simple data container class, what should it be? Class or struct? Mutable or immutable? With or without non-empty constructor? Examples of the above: struct MutableStruct { public string Text { get; set; } public int Number { get; set; } } struct ImmutableStruct { public string Text { get; private set; } ...

array of structures, or structure of arrays?

Hmmm. I have a table which is an array of structures I need to store in Java. The naive don't-worry-about-memory approach says do this: public class Record { final private int field1; final private int field2; final private long field3; /* constructor & accessors here */ } List<Record> records = new ArrayList<Record>(); If I ...

most efficient data structure for a read-only list of strings (about 100,000) with fast prefix search

I'm writing an application that needs to read a list of strings from a file, save them in a data structure, and then look up those strings by prefixes. The list of strings is simply a list of words in a given language. For example, if the search function gets "stup" as a parameter, it should return ["stupid", "stupidity", "stupor"...]. I...

How are regular and composite indexes implemented in RDBs?

In databases like MySQL or Oracle, how are indexes implemented? I think regular indexes are stored as B-trees, but couldn't find anything about composite indexes that index on multiple columns. I'm looking for the names of the data structures used so I can research them. More generally, where can I find more such information about datab...

Is it possible to have a linked list of different data types?

Hi All, This is just another interview question------- Can we have a linked list of different data types i.e each elements in a linked list can have different structure or union elements.If its possible can u please explain me with an example. Thanks and regards Maddy ...

If you were organizing books in a library, how would you store them and what data structure would you use?"

I would use a hash table and use ISBN number as key. As this will give me a look up time of O(1)....as avg time of look up in hash table is O(1).... we can also use Binary search tree.....look up time is O(nlogn)... What data structure would you guys use and why? ...

How to print/extract information listed under a column from two dimensional array in Perl?

I have a output file which is a two dimensional array (this file was output generated after running script written to produce 2D array) and I have to read information under a particular column, say column 1. In other words, how do I read and print out information listed, corresponding to all the rows, under column 1. Any suggestions? _...

What is the best way to represent the levels in a 2D side-scroller?

I've no games programming knowledge and have oft wondered how the levels in 2D games such as Mario and Sonic (etc) are stored. 'Stored' as in how is the data (ground, platforms, buttons, lifts, etc) stored. I.e. obviously a level in mario is NOT some kind of very wide image which is moved from left to right. ...

How to represent a 2-D data matrix in a database

I have a data set which consists of an ID and a matrix (n x n) of data related to that ID. Both the column names (A,B,C,D) and the Row names (1,2,3) are also important and need to be held for each individual ID, as well as the data (a1,b1,c1,d1,...) for example: ID | A | B | C | D | 1 | a1 | b1 | c1 | d1 | 2 |...

Why isn't the two dimensional array in Perl printing correctly?

Handling two dimensional arrays in Perl is giving me a headache. Anyway, the following is my question: I have a loop which pushes an array, say @twoOneArray, into another array, say @twoDimArray, and then is reset before the next iteration of loop begins and then again is pushed into @twoDimArray with new set of values. When I print thi...