All Questions
Tagged with container or collections
355 questions
1
vote
2
answers
83
views
Class template, custom container
So I wrote this class template for a custom container. Basically, it stores elements and their occurences. When an element is pushed into the container, if it ...
5
votes
4
answers
898
views
Reviewing custom array List class of java
I am using JDK 12 and I have developed the custom array list in java with a basic understanding Please let me know if there are any flaws in it that I can correct the same
First the POJO class
<...
1
vote
4
answers
138
views
Get a random member of a container
It was not obvious how to get a random member of a container. So I wrote a function to retrieve it given a generator.
...
3
votes
2
answers
1k
views
Adding/removing songs to a playlist
This is a simple Java application, which adds songs to a playlist, removes songs from playlist based on indexes. A database is not used in this. I am creating dummy data through a ...
2
votes
2
answers
2k
views
C++ ring buffer using some C++ 17 and coming C++ 20 std::span
When I heard about the new Linux I/O interface io_uring I searched about the ring buffer.
I then thought I may replace my safe queue which is base on C++ 11 ...
3
votes
1
answer
96
views
Container that holds objects of various types, and can be searched for an object convertible to a given type
I built a container that can hold objects of various types, and look up an object convertible to a given type. I wrote something about my intended use-case here:
https://stackoverflow.com/questions/...
5
votes
1
answer
161
views
Code to pick buckets for a list of value
In my current project, I came across a scenario where there will be two sorted list of Decimal values. Let's call them ...
5
votes
3
answers
2k
views
reverse a list of generic type
Q: Given a list, reverse the order of its elements (don't use
collections).
Here is my solution:
...
2
votes
1
answer
103
views
transform list to array
Q: Write a method that transforms a list into an array (don't use
collections or already implemented methods in lists, make your own
method)
I've come with this solution:
...
10
votes
2
answers
2k
views
IList<T> implementation
I was wondering about the possibility to create an implementation of IList<T> that is faster than List<T> using C#, ...
3
votes
1
answer
364
views
LinkedList Swift Implementation
Linked List Implementation in Swift
Swift 5.0, Xcode 10.3
I have written an implementation for a doubly linked list in Swift. As well, I decided to make the node class private and thus hidden to the ...
0
votes
2
answers
1k
views
A java program that gets a key-value pairs from a textfile, which should also print in a matrix/table like [closed]
I just want to get some advice about code optimization. How can I make this more OOP? How many class should I have for this kind of task? My code already works but I was told to use OOP in a way that ...
4
votes
0
answers
100
views
C++14 AtomicRoundRobinPool for sharing a pool of keys
The idea here is that we have some resource that is relatively very expensive to generate, but once we have a bunch of them in a pool, we can keep reusing them instead of generating new ones. "HTTP ...
1
vote
1
answer
714
views
Fast insert, fast removal and fast access object pool C++ container
I just want to gather some feedback about this container, in my view it solves the problem of common data containers which don't have fast access and fast deletion. I want to admit that I have not ...
4
votes
2
answers
948
views
A polymorphic union in C++
Sometimes I use std::unique_ptr<BaseClass> when all I really want is polymorphism. For fun, I made this container that skips the heap allocation. The ...
4
votes
0
answers
146
views
Generic Macro Generated Interval Heap in C
When I saw this amazing data structure I couldn't stop myself from trying it! I first sought resources such as this and an article about it here. It basically works as a Max-Heap and a Min-Heap at the ...
2
votes
1
answer
590
views
Force ConcurrentDictionary in a Singleton Registry to Collect Removed Items/Space
I have the following class which is used in a WebApi AspNetCore application as a singleton instance to store Strategy objects (reference type). The class is
...
2
votes
0
answers
95
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 ...
3
votes
1
answer
137
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
0
answers
66
views
Iterating in a list of data and search data in another datatable
I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.
Loading data from ...
2
votes
1
answer
2k
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 ...
3
votes
3
answers
480
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
1
answer
184
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
1
answer
881
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 ...
5
votes
1
answer
383
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 ...
9
votes
1
answer
238
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 ...
4
votes
3
answers
719
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
0
answers
184
views
Simple generic macro-generated containers [closed]
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:
...
1
vote
1
answer
574
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
3
answers
4k
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
1
answer
107
views
java.util.Set extension/implementation
Lately, I was working on some experimental java.util.Set extension, IdSet:
...
0
votes
1
answer
145
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
896
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 ...
4
votes
1
answer
162
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 ...
16
votes
2
answers
50k
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
3
answers
803
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 ...
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 ...
8
votes
3
answers
3k
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
1
answer
78
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
31
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:
...
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
1
answer
62
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 ...
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 ...
4
votes
1
answer
102
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 ...
4
votes
2
answers
770
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 ...
2
votes
2
answers
113
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
...
8
votes
3
answers
188
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
124
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
531
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 ...