collections

Ruby on Rails - Trouble looping through partial using collection

I am having issues using the :collection command for a partial within a form I am creating in rails. I would ideally like to use the :collection command, so I can easily manipulate this section in my .rjs templates (the form will submit and reload the form when the check box is changed, it's a to-do list). This code works: <% for...

Java Collections (LIFO Structure)

Hi, I am looking in the Collections framework of Java for a LIFO Structure (Stack) without any success. Basically I want a really simple stack; my perfect option would be a Deque, but I am in Java 1.5. I would like not to have to add another class to my structure but I am wondering if that is possible: Is there any class in the Collec...

SubSonic Collection Top 1

Is there way in next piece of code to only get the first record? Dal.TreeHtmlExportsCollection treeHtmlExportsCollection = new Dal.TreeHtmlExportsCollection().Where(Dal.TreeHtmlExports.Columns.TreeId, treeId). OrderByDesc(Dal.TreeHtmlExports.Columns.DateCreated).Load(); ...

How to modify or delete items from an enumerable collection while iterating through it in C#

I have to delete some rows from a data table. I've heard that it is not ok to change a collection while iterating through it. So instead of a for loop in which I check if a row meets the demands for deletion and then mark it as deleted, I should first iterate through the data table and add all of the rows in a list, then iterate through ...

How to find out whether two ICollection<T> collections contain the same objects

What is the fastest way to find out whether two ICollection<T> collections contain precisely the same entries? Brute force is clear, I was wondering if there is a more elegant method? We are using C# 2.0, so no extension methods if possible, please! Edit: the answer would be interesting both for ordered and unordered collections, and w...

MultiMap implementation

I'm writing a simple IDictionary abstraction in C# that wraps a Dictionary<K, ICollection<V>>. Basically, it maps multiple values to one key. I can't decide whether to remove a key and its empty list when the last item in a values list is removed, or leave it (to avoid instantiating a new collection if the key is reused) and do checks ...

Collection type for representing a hierarchial structure in .Net 3.5

I been experimenting with the different methods for representing a hierarchical structures in memory that would allow for simple and efficient transversal both up and down to discover ancestor and descendant relationships. Does anyone have any suggestions or examples of the options that I have? Is there a collection type in .Net 3.5 th...

Is it possible to initialise a New System.Collections.Generic.Dictionary with String key/value pairs?

Is it possible to create and initialise a System.Collections.Generic.Dictionary object with String key/value pairs in one statement? I'm thinking along the lines of the constructor for an array of Strings.. e.g. Private mStringArray As String() = {"String1", "String2", "etc"} In case this is turns out to be a syntactic sugar kind of...

How to merge a collection of collections in Linq

I would like to be able to fusion an IEnumerable<IEnumerable<T>> into IEnumerable<T> (i.e. merge all individual collections into one). The Union operators only applies to two collections. Any idea? ...

When to use LinkedList<> over ArrayList<>?

I've always been one to simply use List<String> names = new ArrayList<String>(); I use the interface as the type name for portability, so that when I ask questions such as these I can rework my code. When should LinkedList be used over ArrayList and vice-versa? ...

Wanted : review of collection libraries features / issues / performance

I know there are couple 3rd party collection libraries out there (C5, PowerCollections and I guess loads more of other not so complete libraries) as well as the System.Collections.Generics classes. I am however quite unsure which library use to when. I have tried the C5 collections, but some sources claim that they are slower then the de...

ICollection<string> to string[]

i have a generic ICollection. what is the best way to convert to string[]. using dotnet 2.0 ...

Generics and System.Collections

After moving to .NET 2.0+ is there ever a reason to still use the systems.Collections namespace (besides maintaining legacy code)? Should the generics namespace always be used instead? ...

Class inherits generic dictionary<string, IFoo> and Interface

I have a class that inherits a generic dictionary and an inteface public class MyDictionary: Dictionary<string, IFoo>, IMyDictionary { } the issue is that consumers of this class are looking for the '.Keys' and ".Values" properties of the interface so i added: /// <summary> /// /// </summary> ICollection<string> Keys...

IDictionary<string, string> versus Dictionary<string, string>

what is the value of using IDictionary here? ...

'Proper' collection to use to obtain items in O(1) time in C# .NET?

Something I do often if I'm storing a bunch of string values and I want to be able to find them in O(1) time later is: foreach (String value in someStringCollection) { someDictionary.Add(value, String.Empty); } This way, I can comfortably perform constant-time lookups on these string values later on, such as: if (someDictionary.c...

What's Up with O(1)?

I have been noticing some very strange usage of O(1) in discussion of algorithms involving hashing and types of search, often in the context of using a dictionary type provided by the language system, or using dictionary or hash-array types used using array-index notation. Basically, O(1) means bounded by a constant time and (typically)...

Creating a new List

When creating a new list do you specify an initial size or leave it blank? I know by specifying an initial size you avoid having the list reallocate the underlying array every-time you add x number of items but you also add verbosity to your code. Is the minimal performance gain worth adding verbosity and complexity to your code. What ha...

What is the Easiest/Best Way to Get an Array of Values from an Array Collection?

I have an Array Collection with any number of Objects. I know each Object has a given property. Is there an easy (aka "built-in") way to get an Array of all the values of that property in the Collection? For instance, let's say I have the following Collection: var myArrayCollection:ArrayCollection = new ArrayCollection( {id: 1, nam...

How does the Add Method from the NameObjectCollectionBase collection behave?

Why does the Add method on the NameObjectCollectionBase insert at index position 0? Is there a way to insert the new item at the end of the collection? I'm facing this problem in .Net 2.0 I'm not allowed to change the collection. ...