Collections APIs provide developers with a set of classes and interfaces that makes it easier to handle collections of objects.

learn more… | top users | synonyms (1)

22
votes
4answers
2k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
19
votes
2answers
3k views

List<T> implementation for VB6/VBA

Recently I decided VB6's Collection wasn't enough for my needs, so I decided to implement something like C#'s List<T>. ...
18
votes
10answers
745 views

Incrementing an 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 ...
13
votes
2answers
986 views

O(1) lock free container

This is a lock-free Container class. By Container I mean it will hold objects for iteration at a later time. To achieve \$O(1)\$ ...
12
votes
5answers
9k views
11
votes
4answers
506 views

Collection with both Set and List interface

Here's something I wrote a while ago. I needed a collection that was ordered, but also guaranteed duplicates did not occur. So I made a class with both Set and List interfaces. It seems to work ...
11
votes
2answers
13k 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 ...
11
votes
3answers
805 views

Building a better Collection. Enumerable in VBA

VBA's 'Collection' is.... lacking, so, I've been working on a better Collection object that implements many of the features of C#'s Enumerable. This is very much inspired by this question and a follow ...
11
votes
3answers
10k 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 ...
11
votes
1answer
153 views

Array-like container for uints shorter than 8 bits

Follow-up: Array-like container for uints shorter than 8 bits (Rev 1) First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
10
votes
4answers
8k views

Implementation of stack using pointers

Please review my code and let me know how I can possibly improve it. ...
10
votes
3answers
4k views

Sorting numbers using Java Collections.sort()

Input is a file containing numbers in this format: 1.2 3 5.1 2 7 4 6 5 2 9.22 1 0.0 4 3 I am doing the sorting in the simplest way, using ...
10
votes
2answers
350 views

Twitter Streaming Client - Round#2

I've been experimenting with the Twitter Streaming API and would like some critical feedback. Specifically code correctness, code smells, overall structure, and my usage of collections and queues. ...
10
votes
2answers
2k views

Efficient way of sorting a List based on multiple properties using Google Guava

I'm using Google Guava 17.0 library. I have a class named AroundBust containing only two properties id of type ...
10
votes
1answer
445 views

Is my C++11 generic container a good design?

After refactors and refactors and the discovery of very common patterns on many of the classes of the software I wrote, I decided that it would be fine to have something like an arbitrary-keyed map, ...
10
votes
3answers
511 views

Unrolled linked list

I am interested in the performance tradeoffs of linked lists, standard lists and unrolled linked lists. This will depend on various factors including what operation is being performed (e.g. delete, ...
10
votes
2answers
817 views

Sorting a collection

Related to, but not exactly a follow up of this question. After fixing some issues discovered in the last review, I added a little more functionality to the ...
10
votes
1answer
219 views

Allowing user space file-system to (kind-of) keep more than maximum number of files open

The linked code below is meant to be used in a user space file-system (fuse). Given that multiple processes may have multiple files opened on the file-system, the files on the specific user space ...
10
votes
1answer
297 views

Container with sorted by multiple keys

From this question: Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used) This is an example of a multi-index container. Note: this is not a container as ...
9
votes
2answers
116 views

Splitting two lists into OnlyA, Both, and OnlyB

This is a part of my Minesweeper analyzer code that didn't fit into the last question. This code uses FieldGroup which ...
8
votes
2answers
221 views

Efficiently create and sort a Collection

The goal of my code is to sort data into two categories. It must use a local copy of the initial data from Collar (Top View).csv. My code creates a Collection of items called Collars using the initial ...
8
votes
3answers
216 views

Collection that can be modified in a foreach

Sometimes you want to add/remove items from a collection inside of a foreach loop. Since this isn't possible, a common pattern is to add the items to a separate ...
8
votes
3answers
191 views

More imitation of Enumerable in VBA

I was inspired by Me How's question to see how far I could push an imitation of .Net's Enumerable Class. The new functions can obviously handle Collections, but can also handle any collection-type ...
8
votes
2answers
162 views

Container for list of ranges

I made a C++ container of an ordered list of integers, that, in order to save space, I save as ranges: For example, the list \$ \{1,2,3,5,6,7,8,9,20\} \$ is saved in memory as \$ \{(1,3), (5,9), ...
8
votes
1answer
4k 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 ...
7
votes
3answers
103 views

Writing a program to read a maximum of 99 elements in an iteration from a list

I want to read a list of elements and pass a maximum of 99 elements to a function for some logical operations. I have tried this with an array as an example and this code was successful in achieving ...
7
votes
5answers
727 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 ...
7
votes
2answers
2k views

Deallocate all memory in a container of pointers

I want to erase all memory in a container. Currently I'm using this : ...
7
votes
2answers
244 views

Interface-based polymorphic collection

Here is a small C++11 utility collection to store any object that satisfies a given interface. Only the basic concepts are provided, I did not try to create a full collection: ...
7
votes
1answer
54 views

Joining collections… because it's fun

I'm working on a LinqEnumerable class (reviewable here), and I'm no Big-O expert and I'm pretty bad with algorithms, so I wonder what the complexity is for what ...
7
votes
2answers
166 views

Array-like container for uints shorter than 8 bits (Rev 1)

This is a follow-up to Array-like container for uints shorter than 8 bits In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
6
votes
3answers
191 views

Extension method to enumerate a hierarchical object

I have a domain object that I have no control over which itself contains a collection of this same type. This is a classical hierarichal representation like in a tree node hierarchy. I would like to ...
6
votes
3answers
126 views

Detecting available List operations

I'm writing some code which needs to take a generic java.util.List from another source and adapt to the available functions; eg. does it support ...
6
votes
2answers
162 views

Clean, efficient and extensible code for querying collections

I recently wrote code that would query a collection of objects and rank them according to a given criteria and then filter based on an object property. I attach the code below. I would like to know if ...
6
votes
1answer
176 views

Associative container that produces a unique, instance specific handle for each inserted object

It is not always possible to simplify program design by strictly managing the lifetimes of objects. If two objects have unpredictable lifetimes, but one of them needs to refer to the other, a simple ...
6
votes
1answer
757 views

Simple sparse array

Today, I tried to create a really simple sparse_array container adapter. I did not provide all the STL-like functions, only the elementary ones as a proof of ...
6
votes
1answer
76 views

Efficient top k words using MultiMap (Google Guava ext lib JAR)

Basic algorithm: Open document/huge text file Use Map and List to separate the words. \$O(K)\$ time complexity (TC) ...
5
votes
4answers
460 views

Iterate over two collections of equal length

What's the best way to iterate over two collections of equal length? Currently I'm using this: ...
5
votes
3answers
1k views

Inserting interval into a collection

The task is fairly simple. I want to create a collection of intervals and implement an Add method which would insert new intervals to the collection and merge ...
5
votes
2answers
546 views

Concurrent Linked Hash Set

Basically I want to create a concurrent LinkedHashSet which returns proper size too. I am mainly concerned about adding and removing iterations. Suggestions ...
5
votes
2answers
424 views

Converting data when output std container via ostream_iterator

I have a strongly typed enum and std::vector of this type. ...
5
votes
3answers
23k 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 ...
5
votes
2answers
679 views

Optimize method to iterate to over Map<String, List<Object>>

I have a Map<String, List<Object>> multiFieldMap and I need to iterate over its value set and add the value to ...
5
votes
2answers
167 views

UniqueList Class in VBA

I often find myself abusing dictionary objects just for the exist method like this, ...
5
votes
1answer
107 views

Is this a good way to cascade a property?

I'm trying to write a simple game. I have an Entity object, that has a list of Sprite objects. Each Sprite has a position property where it is drawn on the screen. Sometimes, an entity can contain a ...
5
votes
1answer
133 views

One-line initialisation for a constant list with all entries except one from another list

I'm looking to simplify the initialisation of the second constant, preferably to just one line. Any ideas? Anything from Guava or JDK (up to 1.6) is ok to use. ...
5
votes
3answers
169 views

Finding the closest value in a collection in a game-server plugin implementation

I have an array of a instances of an enum type. A random double variable is initialized with a value between 0.... to 1, and should be used to get the closest ...
5
votes
2answers
413 views

Reducing the execution time of Online Community-Even Groups challenge

I have a coding problem for which I have attempted to solve with the below coding. However, my program is assessed as too slow in its execution and thus needs to be optimized to reduce the execution ...
5
votes
3answers
468 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: ...
5
votes
1answer
256 views

Hacker Rank: Extracting digits from a given number and check for divisibility

The problem in question is a coding challenge from Hackerrank: Problem Statement You are given an integer N. Find the digits in this number that exactly divide N (division that leaves 0 as ...