Questions tagged [collections]
Collections APIs provide developers with a set of classes and interfaces that makes it easier to handle collections of objects.
350
questions
0
votes
1
answer
137
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
2
answers
895
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
3
answers
483
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
1
answer
15k
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
1
answer
160
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 ...
4
votes
3
answers
787
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
1
answer
100
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
4
answers
1k
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
1
answer
13k
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 ...
3
votes
1
answer
76
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
0
answers
30
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
3
answers
5k
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
1
answer
2k
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
1
answer
1k
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 ...
0
votes
2
answers
3k
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 ...
9
votes
1
answer
2k
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
2
answers
2k
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 ...
5
votes
3
answers
20k
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
2
answers
106
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
2
answers
756
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
1
answer
319
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 ...
8
votes
4
answers
9k
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
3
answers
185
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
3
answers
118
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
2
answers
512
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
2
answers
1k
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
2
answers
73
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
1
answer
870
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 ...
3
votes
3
answers
126
views
Fill in workbook with data from another workbook
Followup to this question
I made a macro that will fill in data in a workbook that has 65 (24 are user filled) columns and can go as long as 1500 rows.
The macro can import about 1500 rows and 24 ...
3
votes
1
answer
267
views
Finding the lowest possible number of changes to turn one string into another
I've been working on a task: I have two giant strings, both consist of the same characters just scrambled (both consist only capital english letters). The task is to find the lowest possible number of ...
4
votes
1
answer
84
views
Fill a new Workbook with info from another workbook
I made a macro that will fill in data in a workbook that has 65 (24 are user filled) columns and can go as long as 1500 rows.
In an ideal scenario, the workbook has a perfect column that could work ...
4
votes
0
answers
125
views
C++11 Removable connection from emitter or receiver object
Please review my solution for the following problem. I am interested in:
Maintainability
Usability
Logical correctness
Efficiency
Problem:
It has 1+ objects each in separated thread and between the ...
5
votes
1
answer
2k
views
Complete ObservableDictionary
In conjunction with a recent question of mine, I found that an ObservableDictionary would be very handy for my situation, so I decided to implement one.
I've ...
1
vote
1
answer
31
views
Presenting collections for code generation
I've never been too bothered by the lack of present (and thus print) support for Factor collections and other objects, but I've ...
1
vote
1
answer
333
views
Array Wrapper Class
I’ve wrote a small array wrapper class which mimics the built-in Collection for adding and retrieving items. Once the object is created, you set the array capacity and that would not change.
...
5
votes
2
answers
5k
views
Example of adding STL iterator support to custom collection class
I'm trying to create an example of a custom collection with an API meeting the requirements of STL iterator templates, as a learning experience.
The collection used here, a ring buffer, is merely a ...
5
votes
1
answer
130
views
C++ container — variable byte coded numbers list
I'm writing a container for unsigned integers, which uses variable byte coding. It works but some decisions I took look ugly so I would be glad if you gave me some hints for improving the design.
I ...
0
votes
1
answer
1k
views
Scala type matching map
I was working with some complicated generics system, and I found the need to make an abstraction for a typesafe mapping between K[T] and V[T] where T is the same for individual pairs.
In the case ...
1
vote
1
answer
61
views
Create numerical-key array from existing string-key array, with a given string-key as first item
I have an array of available languages for my website, with a short ISO country code as the key for each language. I need to create a new array that contains the same info, but with numerical keys and ...
6
votes
2
answers
1k
views
Iterator of Container of Container
Based on this question I though I would pull together an iterator that iterated over a container of containers.
...
1
vote
1
answer
2k
views
Returning containers from function - C++ [closed]
I've been trying to implement a few interfaces for processing data. And most of the time I do new of container and return a smart pointer to this container. ...
3
votes
1
answer
74
views
Python JIT container type
This is a follow on from this review. Where I am attempting to improve the performance of my rest client.
I have created an container type (as suggested in my previous post) that lazily instantiates ...
0
votes
1
answer
57
views
Find combinations of items in a nested collection
It's a very typical problem that I come across here and there. Imagine that you have a collection of items of any type, and sometimes items are collections themselves; you then need to "expand" them ...
1
vote
2
answers
105
views
Given a list containing dates and the amount spent on each date, display the total amount spent per month
I had an interview yesterday where I was asked to write a function that would take in a list containing a date and the amount of money spent on that date, and to output the total amount spent per ...
5
votes
1
answer
30k
views
Map with case insensitive get, remove and containsKey
I am looking for a Map implementation (with String keys and any generic type for values) that would support getting, removing ...
1
vote
0
answers
2k
views
Custom dictionary class for reading and writing json value to a file
Is my implementation good? The program works as planned, but I wonder if some parts of the code can be made cleaner or more efficient. The file output looks like this:
...
3
votes
1
answer
14k
views
Generate JSON for Map<String, Map<String, List<String>>>
Consider I have a String:
...
2
votes
2
answers
187
views
Vector replacer
I rolled an own vector-like construct with improved performance and got it reviewed. Here is the updated version.
...
2
votes
1
answer
92
views
Getting single element or throwing one of two exceptions
Sometimes I need to get a single thing from a collection but I'm not very happy with the Single extension. It does not differentiate between empty and more than one ...
2
votes
1
answer
1k
views
VBA: Loop all .xlsx files in a folder and produce a list of worksheets and workbooks contained therein
I pieced together this code in answer to the following OP post on Stack Overflow: Get worksheet Names of All .xlsx files in a folder
Task:
The OP basically wanted to loop all .xlsx files in a folder ...