Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [generics]

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

1
vote
0answers
38 views

Typed properties in Java

I tried to build a "typed" property system in Java and this is what I came up with: first the class Properties that any class can use as an attribute (demo code in the end). ...
3
votes
1answer
65 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 ...
1
vote
0answers
15 views

Calculate mean of vector primitive numerical values generically

I'm trying to write a generic mean function for all values within an Vector of generic numerical primitive type. Could the following implementation be possible ...
2
votes
1answer
40 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
2answers
553 views

Optimize OrderBy Generic Method

Here is my OrderBy method which includes concatenated column names. Can this be achieved more efficiently? ...
2
votes
1answer
88 views

AVL height-balanced binary search Tree and Dictionary

Mostly as a learning exercise, and partly as I thought it might be useful, I have written an implementation of AVL trees ( https://en.wikipedia.org/wiki/AVL_tree ). An AVL tree is a height-balanced ...
0
votes
2answers
82 views

Generic function, which populates a collection based on collection interface implementation

As the above title states I have a function that I use to populate a collection's status names, currency names and other information that I do not store in the database. This is my function: ...
2
votes
1answer
43 views

Batch downloading to file or memory

This is likely my first useful piece of Rust code. Planning to crate-ify it. It works. ...
3
votes
1answer
94 views

Map, which contains biomes, which contain landforms, which contain tiles

I am trying to model this: a Map can have multiple child of type Biomes and no parent a Biome can have multiple child of type Landforms and a Map as its parent a Landform can have multiple child of ...
2
votes
1answer
57 views

Rust closure to be called on a cache miss

The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash ...
0
votes
0answers
31 views

Templated JSON parsing methods that work with an element or elements array

Consider the following two Java methods. The first takes a JSON string representing one element, the second representing multiple elements. gson.fromJson() can be ...
2
votes
1answer
61 views

Swift: arrayToTree() where array contains int and nil

I am learning tree on Leetcode. Need to prepare the testing data. It is easy to convert the array to an organized node, where its elements are integers. such as ...
3
votes
0answers
35 views

Generic router in Rust

I am trying to make a router in Rust using Rocket.rs. I'd like to devise a way to use a default router for my more simple db tables that don't require different logic, to prevent rewriting the same ...
3
votes
1answer
248 views

Protected Pointer: a unique_ptr wrapper that auto encrypts and decrypts data in memory

When dealing with sensitive data, it should be protected from modification and unauthorized viewing as much as possible. This is what this ProtectedPtr class aims to do: encrypt your data when you ...
1
vote
3answers
110 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
0
votes
1answer
58 views

Recursive fluent builder

Problem statement I have entities whose relations form a graph. As an example, let's imagine Users and Groups. Each user has a <...
1
vote
1answer
130 views

Implementation of Generic SQL Data Reader

I am using below virtual method to read the data from SQL Data Reader like: ...
1
vote
1answer
298 views

Webservice class with parser using generics

I'm currently building a small web stack in swift for use in my iOS apps. It consists of multiple components and I want to make it resource specific; To that end, I have a ...
1
vote
2answers
184 views

Two similar factory classes to instantiate services

I'm working on building a library to help you bootstrap the development of a Java API. The premise is, you can have your controllers implement interfaces like ...
0
votes
1answer
122 views

Generic Binary Search Tree Implementation in Java

There is an implementation of Binary Search Tree. This is kind of based on Set Theory that duplicates are not allowed but an attempt to adding the same node twice will replace the older node. BSTNode ...
1
vote
1answer
83 views

Fisher-Yates shuffle Java implementation

This is my attempt at an implementation of the modern Fisher-Yates shuffle in Java. I'm not sure if it can be made more efficient, but I did my best to make it as simple as possible, and I learned how ...
4
votes
1answer
178 views

C# cache controller (Followup)

This is a followup to the question: C# cache controller Suggestions taken onboard from previous feedback, and refactoring to shorten the code in the calls to the cache controller by allowing queries ...
1
vote
1answer
33 views

Numbers adder via generics

This method add all numbers in list and return it as double ...
0
votes
1answer
28 views

Program to check if heap order is correct or not

There is a Java program to check if a Heap (Min) is in the correct order. Heap Order means the parent is less than both left child and right child. ...
1
vote
1answer
73 views

Generic Linked List (header-only and non-intrusive)

Although I should know better, I wrote my own linked list implementation in C. My goal was to make it a true generic collection, with no need to modify the structure being listed. I only ...
0
votes
1answer
105 views

Saving Reddit posts and comments from JSON into ArrayLists

I'm trying to get and save in an ArrayList Reddit posts and comments. The code is very similar for both: The RedditThing is a parent of RedditPost and RedditComment: ...
5
votes
1answer
61 views

Game asset manager

I've been using Monogame for hobby game development for the last year now. My game assets aren't large so I usually load them all on startup. I would have a static AssetManager class with a ...
24
votes
11answers
5k views

Own implementation of Lazy<T> object

The problem with the original Lazy in C# is that you have to put the initialization in the constructor if you want to refer to this. For me that is 95% of the ...
1
vote
0answers
39 views

C Generic Sorted Doubly-Linked List

I just finished this big project. Its is called SortedList and it is implemented using a Doubly-Linked List. It data is of type ...
5
votes
3answers
874 views

Fastest FIFO with macros for use embedded devices

UPDATE (a year later) Since this post the code has turned into a small library called fifofast and is hosted on github under the MIT License. This note is meant for anyone who stumbled across this ...
4
votes
1answer
183 views

Mapping DataTable to a concrete type

I have an extension that adds values to a class and I was wondering if there was a faster way to do this. Does a for loop execute faster or would a LINQ query do better? ...
5
votes
1answer
87 views

Service for generating faked objects

I'm using the Bogus library to mock up some data for testing. This is my main method demonstrating how the faking service should be used: ...
7
votes
2answers
781 views

Generic Dictionary Equality Comparer

I created the below comparer to allow me to use a generic dictionary as a key to another generic dictionary. My GetHashCode implementation creates a hash based on ...
1
vote
2answers
186 views

Performance of generic VS non-generic method (array generating function)

I'm trying to improve performance for a generic function that turns a string into a multidimensional array. Expected input: A string that was generated by the function ...
3
votes
2answers
182 views

Unit testing a generic interface: proposal to avoid test duplication for different generic types

I'm looking for feedback on a way to avoid massive code duplication on unit tests of a generic interface. It is expected that the interface will have several dozen implementations with common ...
2
votes
3answers
285 views

Get collection of objects from CSV string and vise-versa

A generic class to get object collection from csv string. I would like to know if there's any better way? Converter class ...
8
votes
3answers
9k views

Serialize C# objects of unknown type to bytes using generics

Usage example var qm = new QueueMessage("foo", 99); var ba = ByteArraySerializer<QueueMessage>.Serialize(qm)); Class that performs the serialization / ...
9
votes
5answers
3k views

Calculate fingerprint for an object

I need to store serialized objects in a database and I want to avoid duplicates. In order to be able to tell wheter an object is already stored, I have to compare them somehow. My idea was to ...
4
votes
4answers
748 views

Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found

I wanted to in the most generic way possible write a method in C# to achieve the following. Take in a string, a set of objects, and a function to access the field of a given object Look at all of the ...
2
votes
1answer
93 views

Handling related generic type parameters

In answering a question on StackOverflow, it occurred to me that a more generic version of GroupBy for C# that delegated membership in each group to a class could ...
2
votes
1answer
150 views

Curiously Recurring Template Pattern (CRTP) implementation

I'm implementing Curiously Recurring Template Pattern(CRTP) in Java as follows. The Interface: ...
2
votes
1answer
92 views

Linked List using templates and smart pointers

I have an implementation of Linked List with push, pop, ...
0
votes
0answers
53 views

Calculate area of different geometric figures

I would like to write cleaner, reusable code in Fortran. Is the following piece of code a good way to implement generic functionality? Is the linebreaking and indentation ok? It should be Fortran90. ...
1
vote
1answer
127 views

Queue implementation using unique_ptr

I am trying out different data structures to learn more about smart pointers. I have created a queue implementation which has push, ...
1
vote
0answers
187 views

E-commerce site for posting advertisements

I am developing an e-commerce website in ASP.NET MVC. Users can post advertisements of different types on the site. I am using inheritance to define my Ad types, and this review is mainly about ...
2
votes
1answer
432 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 ...
7
votes
3answers
1k views

Heap implementation for numeric types

I am trying to improve the quality of my code as well as trying to study the Heap data structure. I have implemented a minHeap (Heap in which minimum value nodes ...
3
votes
2answers
205 views

DFS for Graph search with generic data types

This question is a follow up to this. I am learning Graph data structure and have implemented DFS and BFS in a way that it can handle data types other than int. These function try to search an end or ...
1
vote
1answer
41 views

C++ - Graph implementation for data types other than int

I am learning graphs and most of the implementations that I see are meant for int. So, I decided to code an example that can take other data types such as ...
7
votes
2answers
170 views

C++2a comparison-based topological sort algorithm

Here's my attempt at a C++2a Standard Library–friendly "topological sort" algorithm. There are several areas of interest here: The algorithm is comparison-based and in-place, just like ...