Collections API's provide developers with a set of classes and interfaces that makes it easier to handle collections of objects.
2
votes
5answers
200 views
Performance: Divide group of numbers into two groups of which the sums are equal
I have a piece of code that divides a group of numbers into two groups of numbers of which the sums are equal.
I created this because of a StackOverflow question: ...
0
votes
1answer
59 views
Java concurrent Map of List
I need concurrent HashMap of List as value with following behavior:
count of read/write ops approximately equals
support add/remove values in lists
thread safe iterations over lists
After some ...
-1
votes
2answers
79 views
What is a good name for bidirectional dictionary structure? [closed]
I'm writing a generic bidirectional dictionary which will be a part of a (somewhat) public API. This is how the dictionary works:
It will hold key-key pairs where key1 and key2 will be two different ...
0
votes
1answer
46 views
Does refactoring a while loop increase CPU usage
While upgrading our code base to take advantage of new features in .Net 4.5, I'm trying to refactor our take of the classic Producer/Consumer algorithm, but I'm concerned my refactoring is going to ...
3
votes
3answers
113 views
Cached empty collections
I often find myself in need to create empty collections. One of those days several years ago, I wrote something like the following to address that:
public static class Array<T>
{
// As a ...
3
votes
2answers
73 views
How would you improve this object model design to get around Covariance Issues with ObjectModel.Collection<T>?
Consider the following simple relationship.
Code
[DataContract(Name = "Wheel")]
public class Wheel { }
[DataContract(Name = "OffRoadWheel")]
public class OffRoadWheel : Wheel { }
...
8
votes
2answers
834 views
Add/Remove items thread-safely in List<T>
Recently I had to lock collections (of type List<T>) when items were added or removed. Because several collections were used in given code instead of creating helper methods for each collection, ...
7
votes
5answers
300 views
A simple unrolled linked list implementation
I tried to implement an unrolled linked list in C#. I only needed to add things and clear the whole list so I didn't implement IList<T> (I tried but it was getting too complex, so I postponed ...
3
votes
1answer
575 views
Thread-safe LRU Dictionary in C#
Can't seem to find one, so trying to build a very simple but fast implementation. Thought I would post on SO for review/feedback, and so that others can just copy/paste for their own use.
I'm using a ...
3
votes
1answer
111 views
Learning Java Collections Framework
I am learning Java Collections Framework. Can someone look at this code for generating all subsets of a given set and tell me any issues with it.
import java.util.*;
public class AllSubsets {
...
2
votes
3answers
261 views
ReadOnlyCollection - my alternative to .NET one
I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection.
The goal was: consuming classes should only see what I want to show them, not whole underlying collection.
For ...
1
vote
1answer
287 views
I am trying to re-write the ATM problem using collections. This is for personal learning. Can you please provide your comments
The problem statement is
Write a CashWithDrawal function from an ATM which based on user specified amount dispenses bank notes. Ensure that the following is taken care of Minimum number of bank notes ...
3
votes
2answers
166 views
Iterating thousands of times over large collections: advices
This is a pet project :)
I have hundreds of playlist files .m3u whose many entries have a wrong path. I'd like to fix them programmatically. Suppose one of my .m3U contains the following entry:
...
1
vote
0answers
431 views
Android - get int array from database Cursor
I find this code quite ugly, but in fact, I don't see any finest way to achieve the goal.
private static final String TABLE_NAME = "table_name";
private static final String[] allNeededColumns = ...
0
votes
1answer
246 views
PHP Class to Represent a Type Collection
Here is my attempt at a PHP class to be used as a base class for typed collections. My goals with this are:
to be able to access collection members with foreach
to be able to access collection ...
1
vote
0answers
63 views
Defining transpose on a collection of irregular collections
I was asked to submit my request for code review on http://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here.
This is a follow-up to the post I ...
1
vote
1answer
247 views
card sets class design in a poker game
Looking for opinion on my classes' design. I am trying to come up with the best possible design in the context of Java and object orientation principles. (I have asked some questions about my game ...
4
votes
1answer
261 views
Entity collection best practice (separation of concerns, dependency injection, …)
I build a collection to ensure only valid entities in an array so I don't have to validate after every function / method call as I could rely on the collection to have only valid entities stored.
...
3
votes
1answer
109 views
JavaScript: Whats wrong with this implementation of Collection
I am pretty new to JavaScript and learning the intricacies of this language. I wanted a unique collection which will overwrite while adding if an item already exists else add. Rest of the behavior ...
3
votes
3answers
3k views
What is the most efficient way to convert a Java ResultSet to an Object[][]?
I have a module that builds swing tables based on an Object[][], then I have another module that queries a sqlite database and returns a ResultSet.
I have written a method that converts the ...
1
vote
2answers
337 views
How to delete last element in java.util.Set efficiently?
List<Route> listOfRoutes = routeStopsService.getAllRoutes();
Set<String> listOfStopNames = new TreeSet<String>();
for(Route route:listOfRoutes){
Set<Stop> stops = ...
4
votes
2answers
832 views
Is this collection actually thread safe? Is concurrent Iterating, querying and modifying safe?
This is based on Alexey Drobyshevsky's excellent article Problems with Iteration
At Alexey's suggestion, I implemented his solution using a ReaderWriterLockSlim. Then I fleshed out a ThreadSafeList : ...
11
votes
11answers
414 views
Can you think of a better way to increment this integer when looping through a collection in C#?
I have the following code that loops through a collection of objects and dumps different properties out to Excel. The whole j++ on every other line doesn't seem very elegant.. is there a more elegant ...
1
vote
1answer
237 views
Persisting objects in a ListBox ObjectCollection
I have a C# WinForms app containing a ListBox control, which I populate with objects of type BukkitServer. When an object is added or removed from the list, I want to write them to an XML file. I ...
4
votes
3answers
1k views
Java blocking queue
public class BQueue<T> {
private Queue<T> q = new LinkedList<T>();
private int limit;
public BQueue(int limit) {
this.limit = limit;
}
public ...
2
votes
1answer
112 views
Scala Direction enum with Enumeration and collection usage
I've just implement direction enum
object Direction extends Enumeration {
type Direction = Value
val Up, Right, Down, Left = Value
val pairs = HashSet() ++ List((HashSet() ++ List(Up, Down)), ...
5
votes
1answer
2k views
LinkedHashMap as LRU cache
I have a simple implementation for a LRU cache using LinkedHashMap.
I want it to be as generic as possible.
This is not for production use, just practice, so I don't care
if its thoroughly ...