Questions tagged [collections]

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

2
votes
2answers
4k views

How to observe nested objects

By having two model classes Conversation and Message, what are the best practices to handle the next situation: A conversation ...
3
votes
0answers
37 views

Dependency Container

I'm currently creating my own microframework for learning purpose and I want to make it more powerful by providing a way to register classes and instantiate them (once) only when needed. So here is my ...
8
votes
1answer
152 views

Class containers, filtering and coding practices

Context Usually, when I have to deal with a collection of items (especially objects) I tent to create a container class for that collection (wrapper?). What I mean by that is: when I have to handle ...
2
votes
0answers
57 views

Game involving finding words containing letters from a memorized list

I wrote this Java game where the user memorizes a list, gets given letters and needs to find a word that contains those letters. The player has only a few seconds to enter the word. Example: Program ...
1
vote
1answer
730 views

Set, List and Map equality comparison with Lambda check

I'd like to be able to compare two objects with different equality checks. This should work if they're in a Set, List or ...
3
votes
1answer
69 views

Generic Macro Generated Hashset in C

The Hashset uses open addressing, linear probing and Robin Hood hashing for handling collisions. It comes with insert and remove ...
2
votes
1answer
86 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
17
votes
2answers
2k 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)\$ ...
3
votes
2answers
128 views

Efficient way of flat mapping a range of a multidimensional random access collection

I've recently answered a question about reading elements from an array of arrays. A way it could be interpreted is that the OP wanted to read a range that could span over multiple subarrays of the 2D ...
1
vote
1answer
68 views

Wrapper for a standard STL-container

In the codebase I support, I found the following code. I am interested in your opinion about its expediency and especially the expediency of redefining the operator(). ...
9
votes
2answers
2k 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 ...
8
votes
0answers
109 views

Binary Search Tree Implementation in C++17

I am a hobbyist computer programmer trying to learn modern C++ (in this case C++17). I thought it might be an interesting challenge to write a Binary Search Tree similar to ...
1
vote
0answers
74 views

Data structure that is fast to read and modify

I'm working on an apllication that needs to process a lot of objects in realtime. I've separated the logic from the UI so that it isn't as much of a mess. The basic idea is that every tick I'm trying ...
6
votes
3answers
5k views

Find a prefix of a query string in the values of a Map

I have a hash map which maps to some strings which serve as prefixes and are of small length (max length is 6): ...
1
vote
0answers
65 views

Further dive into filtering using IPredicate

Preface This is a follow up to my previous post from not long time ago about containers and filtering. This post can be found here. Now, I will attempt to expand what I have learnt from the answer ...
4
votes
3answers
83 views

My implementation of a for_each function that traverses a std::container by some step size integer N

As my answer to Iterating over an odd (even) elements only in a range-based loop, I wrote this function, with the following driver program and output: ...
2
votes
0answers
47 views

Simple generic macro-generated containers

In order to learn macros in C I decided to make a generic data structures generator for other projects that I have in C. The main macros are the following: ...
0
votes
0answers
20 views

Extension to BindingList<T> that allows for cancelable notifications of changing and deleting

This is an extension of the System.ComponentModel.BindingList<T> class that allows for notifications of item changing and deleting. These notifications ...
4
votes
3answers
509 views

Pass IEnumerable<T> as an argument of method and repository pattern

I've seen tutorials of Unit Testing and I've never seen that IEnumerable<T> used as an argument of method. All authors use ...
0
votes
1answer
91 views

java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
0
votes
1answer
56 views

Breaking a 32-bit value into bytes for an ArrayList

I am very new to Java and its collections and I'm trying to figure out "best" way to populate an ArrayList<Byte> in Java. In particular, I'm trying to take a ...
5
votes
2answers
863 views

Going from IQueryable<IEnumerable<myObj>> to IEnumerable<myObj>

I have a "GetPersonsPerDepartment()" method returning a IQueryable<IEnumerable<Person>> while I'm trying to get a simple ...
5
votes
3answers
317 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 value'...
2
votes
1answer
7k views

ArrayList for Shop implementatin

Problem statement: Design a system for the following scenario: An item list contains item code, name, rate, and quantity for several items. Whenever a new item is added in the list ...
4
votes
1answer
136 views

Collections management with many derived elements

I've been told few days ago that using is is a code smell and anti-pattern. I used it in an game to filter some elements of a collection (the inventory of the ...
5
votes
2answers
2k views

Ring Buffer Implementation in C++14

A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than moving the data. Ring buffers are often used in embedded computer design. ...
4
votes
3answers
109 views

Really easy synchronised access to an IEnumerable without boilerplate code

Often when reading data from a sequence (IEnumerable<T>) in multi-threaded code, a consistent snapshot needs to be taken inside a ...
4
votes
1answer
57 views

General use multi-dimensional container using operator[]

This is a followup to a previous question of mine on same subject. Context I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional ...
8
votes
4answers
765 views

Alternating items in a collection

Is there any better way how to mix items in list? In my example: I want to sort list items as male, female, male, ... My solution is probably very time and resource demanding. Can I do it somehow with ...
3
votes
1answer
7k views

Intersection of a Stream of Collections

An API (I have no control over) gives me a bunch of Collections (Lists, to be precise,) and I need the elements that are common ...
6
votes
2answers
645 views

Moving elements satisfying a predicate from one container to another

I've implemented a C++ algorithm that moves elements satisfying a given unary predicate from one container into the other, deleting them from the input container. This is my implementation: ...
3
votes
1answer
51 views

Time series dataset with temporally enforced object lifetime

The purpose of this class is to have that can maintain data set where the samples contained within the set have an expiry time. Samples are inserted in chronological order. In an attempt to memory ...
2
votes
0answers
19 views

How to connect a propery class/object with a collection (its database class)?

I'm struggling with organizing my code regarding 'best practise'. In particular how I link a class with its collection class. I've 2 classes: ...
4
votes
3answers
4k views

Custom Implementation of ObservableDictionary

I recently found myself in need of an IDictionary<TKey,TValue> implementation that was observable from a WPF UI. Since the .Net framework does not provide ...
2
votes
1answer
468 views

Filtering a log file and extracts by different properties

I have implemented a program to extract a log file which contains a header line, followed by zero or more data lines, in comma-separated value format. The file consists of 3 columns. The first column ...
2
votes
1answer
980 views

Method to return statistics from a collection with O(1) time and space

I have a DelayQueue, and the goal is to collect statistical information from the collection in O(1) time and space from ...
1
vote
2answers
1k views

Variadic template class that stores a vector of each type given [closed]

I'm exploring the possibility to generalise a class of mine that stores some entities. I like it to be able to keep entities of several type, given as template arguments. To explore the possibilities ...
8
votes
1answer
460 views

Generic Skip list implementation in C++ Version 3

This is a follow up of Non generic Skip List implementation in C++ Version 2 If you don't know what a Skip list is: https://en.wikipedia.org/wiki/Skip_list I tried to incorporate as much ...
3
votes
2answers
373 views

Non generic Skip List implementation in C++ Version 2

Edit: This code was reworked and repostetd under a new question: Generic Skip list implementation in C++ Version 3 This is a follow up of: Non generic Skip List implementation in C++ If you don't ...
4
votes
3answers
16k views

Generic sum method for a Collection<Number>

While answering this question, I wanted to use a generic sum of Collection function. Java doesn't have a native method, so I wrote one. There are a couple things ...
2
votes
2answers
78 views

Summing payments by year using Java Streams

I'm using 1.8.0_162 version of Java and here is my task about stream framework ...
4
votes
2answers
172 views

Non generic Skip List implementation in C++

Edit: This code was reworked and repostetd under a new question: Non generic Skip List implementation in C++ Version 2 To sharpen my C++ skills I tried to implement a skip list. I was quite happy ...
7
votes
1answer
102 views

Custom container for iterating over combinations of elements from multiple sets

Motivated by some SO quesitons [1, 2] I made an attempt at implementing a custom container with a bi-directional custom iterator for iterating over all combinations of elements from multiple sets. I ...
6
votes
4answers
6k 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: ...
8
votes
3answers
157 views

Build clusters from connections (virus propagation)

The scenario is the following: There is a list of persons and places where those persons visit. Each person is connected to a single or multiple places. See the picture below, where O[i] represents ...
4
votes
3answers
107 views

List mapping of large data set from file

I have a list of items 116 thousand and my mapping function is taking quite some time to process. I am using the file helpers library to write the CSV to disk but its the for each that is taking ...
9
votes
2answers
225 views

Multi-dimensional container using operator[]

This is a late followup to a previous question of mine on same subject. Context: I want to have a tool that allows to use all the C++ goodies (algorithms, for loop on containers, etc.) on a ...
2
votes
2answers
332 views

Wrapper for a raw array so that it can be passed to templates expecting Standard Library containers

I am working with a code base where unfortunately I cannot replace all raw arrays with std::array. The spec provides no guarantee that the memory layout of a ...
5
votes
2answers
63 views

Filter queries three orders of magnitude slower than insertions

As part of a C++ library, I'm implementing a filter class for approximate set membership and abundance queries. The filter has two primary operations: ...
4
votes
1answer
228 views

Fast insert unique container

I posted the same question at StackOverflow then I got an advice to post it here. Original question: https://stackoverflow.com/questions/49998297/fast-insert-unique-container I have to store ...