collections

Collections.max function for iterable<Integer> in java

The Java Collections.max takes only a collection of a sortable object. However since the collection is not necessarily sorted, I don't see any reason not to implement the same max function for iterable types. Is there a max method for Iterable<T extends Comparable<? super T>> in java's standard library? ...

Overload [] operator in AS3

I just finished writing my own collecion class, and i'd really like to make it iterable with the for each or the simple for construct, or just to access elements with the collection[key] notation. I've written a getElementAt(index):MyOwnElement function, but using it, is not as sexy as using the square brachets, don't even let me start ...

Does a List<T> guarantee that items will be returned in the order they were added?

Does a List<T> always guarantee that items will be returned in the order they were added when enumerated? Updated: Thanks for all the answers folks, puts my mind at ease. I had a quick poke around the List<T> class with .NET Reflector (should've probably done that in the first place) and indeed the underlying store is an array of T (T[]...

DateTime as key in a SortedDictionary<K, V>

Can I safely use DateTime as a key in a SortedDictionary<K, V> without implementing my own IComparer? I've tried it and sort order is maintained and importantly for my purpose the .ContainsKey<T> method works as expected. But I just want to double check before committing myself down this road. Update: Thanks for clearing that up folks....

Why do C# collection initializers work this way?

I was looking at C# collection initializers and found the implementation to be very pragmatic but also very unlike anything else in C# I am able to create code like this: using System; using System.Collections; class Program { static void Main() { Test test = new Test { 1, 2, 3 }; } } class Test : IEnumerable { p...

C#, a String's Split() method

C#, a String's Split() method, how can I put the resulting string[] into an ArrayList or Stack? ...

Is there a java hash structure with keys only and no values?

I'm looking for a structure which hashes keys without requiring a value. When queried, it should return true if the key is found and false otherwise. I'm looking for something similar to Hashtable<MyClass, Boolean> except insertion requires only a key and queries only ever return true or false, never null. ...

[Java] What is the best way to check if an object is from another(say fixed) list of objects?

Currently, I create a HashMap with Object Id as key and 1 as value. And the method asks for Object/Id and checks if there is a matching key. Is that ok? Or, is(are) there better alternative(s)? ...

Is there an overview of the most common algorithms?

I'm looking for an overview of algorithms, you need every now and then. If there is a problem, you either do reinvent the wheel or spend a lot of time searching for an algorithm to a common known problem which has been solved a hundred times before. Best one would be a website with sorted algorithms, like: Compression ... Decryption...

How to deal the item of a collection which belongs to another collection

Hi, I have a problem in reading and loading items of a collection which belongs to another collection in vb 2005.Those are all nodes of xml file. For exemple: Toto is a node in xml file, an item of collection Tocollect and also a child-node of Tocollect, Tocollect is an item of Collect and a child-node of it. When write the code, are ...

A collection of ranges

Imagine a scenario where, using xml, the user is able to specify ranges in a flexible manner, using any combination of "gte", "gt", "lte", "lt" or "eq". Here are some examples <rangeElement gte="0" lt="5" ... /> <rangeElement gt="3" lte="7" ... /> <rangeElement eq="5" ... /> <rangeElement gt="10.5" ... /> Now what I need is two class...

BlockingQueue: put() and isEmpty() do not work together?

I would like to have a SynchronousQueue where I insert elements from one thread with put(), so the input is blocked until the element is taken in another thread. In the other thread I perform lots of calculations and from time to time want to check if an element is already available, and consume it. But it seems that isEmpty() always re...

Best way to remove multiple items matching a predicate from a c# Dictionary ?

I need to remove multiple items from a Dictionary. A simple way to do that is as follows : List<string> keystoremove= new List<string>(); foreach (KeyValuePair<string,object> k in MyCollection) if (k.Value.Member==foo) keystoremove.Add(k.Key); foreach (string s in keystoremove) MyCollection.Remove(s); The re...

Using the .NET collection editor without using a property grid control

I have a PropertyGrid on my form. My boss thinks it's ugly. Uncouth. Unsophisticated. He wants a nice, neat, clean form. Here's the catch: One of the properties is a collection of our home-grown objects. He likes the collection editor for this collection. I know I can build my own collection editor. But is there a clean, simple solutio...

Form Collection item coming up as null

hi everyone, I am trying to use form collection and this is what i am using to submit the form <%=Html.ActionLink("Update", "Calendar", ViewData["sub"], new { onclick = "this.form.submit();" })%> just for the heck of it i tried replacing it with a dropdownlist that retains its value and all of a sudden i get all my form collection ...

What generic collections in C# are IXmlSerializable?

Are any of the .NET generic collections marked as IXmlSerializable? I've tried List<T> and Collection<T> but neither work out of the box. Before I roll my own collection<T>, list<T>, or dictionary<T> class, I thought I'd check to see whether Microsoft had included something that does this already. It seems like basic functionality. EDI...

Good uses for Apache CollectionUtils

I found the CollectionUtils class a year or so ago and a few of the methods like, collect, and transform seem really cool, however, I have yet to find a use where it would not by syntactically cleaner and\or easier to just write the logic with a simple loop. Has any found a unique\useful use for these methods (transform, predicatedColl...

Best C# data structure for random order population?

In C# I have a use case where I have a mapping from ints to collections. the ints are a dense (but not packed) set from 1 to n where n is not known. The cells will be loaded in random order. the marginal cost of each cell should be ideal (as good as a List<T> or T[]) I'd like to have the cells default filled on demand What is the bes...

Collections optimized for concurrency in .Net

In the java world there is a set of classes optimized for concurrent tasks. I assume there is something similar in .Net, but after a quick search in MSDN I couldn't find anything. I was looking for a queue with fairness policy to be used in consumer/producer situations. Thanks. ...

C# - Collections and casting

I have a base class, BaseObject, and a number of classes which derive from BaseObject (DerivedObject1, DerivedObject2 etc) I have a collection of BaseObjects in which I storing the derived objects. The code I use to do this is: // declaring and initializing the idictionary public IDictionary<ulong, BaseObject> ObjectList = new Dictiona...