collections

Rewrite type specific method as generic

I have a method (shown below) that I discovered can be reused in code elsewhere if I could turn it into a generic method, but am struggling with the syntax and could use a bit of help: Sample: private List<IndexEntry> AddParentReferences(List<IndexEntry> listWithoutParents) { List<IndexEntry> listWithParents = new L...

Which sorted collection implementation has the smallest memory footprint in Java?

I'm not unduly bothered about read/write performance (though obviously as fast as possible is always good), rather I'm looking for a sorted collection implementation that is as memory efficient as possible. Any suggestions? ...

Java: Equalator? (removing duplicates from a collection of objects)

I have a bunch of objects of a class Puzzle. I have overridden equals() and hashCode(). When it comes time to present the solutions to the user, I'd like to filter out all the Puzzles that are "similar" (by the standard I have defined), so the user only sees one of each. Similarity is transitive. Example: Result of computations: A ...

adjacency list of a directed weighted graph

I am using adjacency lists to represent a directed weighted graph and based on the example code provided by this SO question, I have created the following: import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.Set; public class _Graph { private Map<String, Link...

How to modify ILookup object in C# 4.0?

Before .NET 3.5 was released, I use Dictionary<TKey, List<TValue>> for containing data. But I just found that .NET 3.5 provides new collection type that is ILookup class that can represent my old complex data type. I always create ILookup object by using LINQ extension method (ToLookup method). But I do not know how to modify ILook...

How to associate an iterator to a collection in OCaml

I have these two classes in OCaml class type ['a] collection = object method add : 'a -> unit method clear : unit -> unit method iterator : unit -> 'a iterator method remove : 'a -> unit end class type ['a] iterator = object method hasNext : unit -> bool method next : unit -> 'a end And I need to cr...

Combining use of wildcard in methods and in type of receiver in Java.

Hi, I am trying to use a combination of wildcards in the type of the receiver and in the type of an argument to a method in Java. The context is that of defining a container. Now, the type Container should not admit insertions whatsoever, since this type does not specify the type of the contained objects. However, if the underlying data...

Best way to implement "ReOrderable Collection" and Persist it to database

Hi, My domain object : public class MyDomainObject { public Guid Id { get; set; } public string Name { get; set; } public int DisplayOrder { get; set; } } Assuming sample data : var list = new List<MyDomainObject>() { new MyDomainObject {Name = "Element1", DisplayOrder = 0}, ...

Enumerating a collection, then modifying it, what is the precedent for throwing an exception?

When enumerating a .NET collection, MSDN states that: An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined. What exactly does "irrecoverably invalidate...

Is there an version of List that has Add and Remove events

I need a .net Collection that has Add and Remove events. Is there a premade version that has that? For example, I would update some internal counter when a user adds an item to the list via the event. (Not really what I plan to do.) ...

How to convert List<Company> to List<ICompany>

Hi I would like to convert List<Company> to List<ICompany> ICompany is an interface which Company implements. public List<ICompany> FindAll() { List<Company> companies = new List<Company>(); var query = from c in _scope.Extent<Company>() select c; companies = query.ToList(); return companies.ToList<I...

java function - print(collection c) ?

Hi. I'm trying to learn java better and I got one question. Say I got two collections, an ArrayList and a LinkedHashSet. Is it possible to make a function like this: void print(collection c) { for (object tmp:c) { System.out.println(tmp); } } ...

ASP.Net and Collection

I want to build an N-Tier web-application , for shopping cart. I want to follow the concepts collections. That is retrieve data from db, fill it in collections and bind collections with asp.web and html controls. Or simply i can say , i want to know how to use collections with ASP.Net controls or Some good tutorials or links to learns ...

What's the max items in a List<T>?

Anybody know what the max number of items in a List is? How do I increase that size? Or is there a collection that takes infinite items? (as much as would fit in memory, that is) EDIT: I get an out of memory exception when Count = 134217728 in a list of ints. got 3Gb of RAM of which 2.2 are in use. Sound normal ...

Convert List<Cookie> to CookieCollection in C#

Let's say I have List<Cookie> and I want to convert it to a CookieCollection. What's the easiest way to do this? I know I can use a foreach loop, but isn't there a way to instantiate it with code similar to this? List<Cookie> l = ...; var c = new CookieCollection() { l }; When I try to compile that though, I get the error: The be...

TreeSet acting weird

I'm having a weird problem with TreeSet (sortedNodes) and ArrayList (nodes). In my program, I have in a method called from Event Dispatch Thread (from ActionListener) these lines: System.out.println("nodes: "+nodes.size()); sortedNodes.addAll(nodes); System.out.println("sortedNodes: "+sortedNodes.size()); Probl...

Overriding HashSet's Contains Method

Hello StackOverflow... Could anybody tell me how I can override HashSet's contains() method to use a regex match instead of just equals()? Or if not overriding, how I can add a method to use a regex pattern? Basically, I want to be able to run regex on a HashSet containing strings, and I need to match substrings using regex. If my met...

Why was Set left out of .NET Collections?

Possible Duplicates: Why doesnt .Net have a Set data structure? C# Set collection? Just curious as to why Sets were left out of .NET collections. It seems like a pretty big omission, and I wondered what the reason might be. BTW I know that there is HashSet in .NET 3.5, but it did take Microsoft a long time to get around to p...

C# Dictionary ContainsValue look up by object attribute

Hello, I have Dictionary<long, Location> PostalCodes . While i m adding new elements to this Dictionary I want to make a lookup to this dictionary and if the Location.PostalCode is not in this dictionary, I want to insert it. Otherwise I want to skip it. So , need to know if the PostalCode is already in the Collection. Cant use it as ...

Deleting an element from one-to-many collection (Java + HIbernate + Struts)

Hi all, I can't delete a child object from the database. From the org.apache.struts.action.Action.execute() method, I am removing the child from the parent's List, and also calling session.delete(child). I've simplified the code below and only included what I believe to be relavent. Hibernate Mapping <class name="xxx.xxx.hiber...