Stack Exchange Network

Stack Exchange network consists of 174 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
3answers
47 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
1
vote
1answer
53 views

Implementation of Generic SQL Data Reader

I am using below virtual method to read the data from SQL Data Reader like: ...
0
votes
1answer
38 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
59 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 ...
1
vote
1answer
31 views

Numbers adder via generics

This method add all numbers in list and return it as double ...
0
votes
1answer
27 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. ...
0
votes
1answer
54 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
55 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 ...
5
votes
1answer
58 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 ...
23
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
30 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 ...
4
votes
1answer
102 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
82 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
490 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
111 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
253 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 ...
4
votes
4answers
747 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
88 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
72 views

Curiously Recurring Template Pattern (CRTP) implementation

I'm implementing Curiously Recurring Template Pattern(CRTP) in Java as follows. The Interface: ...
0
votes
1answer
68 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: ...
0
votes
0answers
46 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
63 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, ...
2
votes
1answer
81 views

Linked List using templates and smart pointers

I have an implementation of Linked List with push, pop, ...
1
vote
0answers
172 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 ...
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
131 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
37 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
146 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 ...
4
votes
1answer
107 views

List of classes to datatable

I'm looking for a function to take a list of generic classes, and map it to different layout of datatable. That means, I can't just directly map my class property names and values to grid, I need to ...
10
votes
3answers
160 views

Generating image gauges from a value, min and max

One of the things I was recently investigating was the ability to generate "gauge" charts—that is, a chart which shows where a value stands within a range of values. As an example, if we know ...
1
vote
2answers
217 views

Generic TryParse extension method for the standard value types

I often need to update properties using the out parameter of the standard TryParse methods. However, use of a property as ...
0
votes
1answer
54 views

Using a wrapper on a primitive as a generic for an interface used for Java lambda

I apologize for that title, lol. I have a Java method that I'm writing where I want to be able to pass in an array of Objects and two interfaces that will be used for lambda expressions that specify ...
2
votes
0answers
32 views

Classical Single Pivot QuickSort implementation in Java using Generics

I have coded the following quick sort implementation. There are few things that still makes this code ugly and redundant. 1. Handling Arrays of Primitives I have to write a separate implementation of ...
2
votes
1answer
96 views

Implementation of generic unordered list in java

This question is a follow-up question of this question. These features are added to the new class - Generic class User is capable of setting the size ...
6
votes
2answers
188 views

Parsing small data into tuples

I'd like to make parsing small samples of data more efficient (from the developer point of view). This means, instead of writing the parsing logic each time from scratch when I encounter something as ...
1
vote
1answer
645 views

Generic Array (Vector) Class C++

I am a mathematician trying to learn how to become a better programmer in C++. I am currently now trying to write the main data structures from scratch. I have now completed a generic array class and ...
3
votes
1answer
124 views

Generic linked list

I provided an answer to a question on SO about a generic linked list. I just had the curiosity of having my code peer-reviewed as I wrote the code specifically for the answer. That is, I have not ...
7
votes
2answers
3k views

Turning a byte array into a C# object whose type is unknown at compile time

I'm trying to turn an array of bytes into a C# object. I only the know the type of the object at runtime. Right now, I'm using the ...
3
votes
2answers
469 views

Monoid type class in C++

I am trying to come up with a monoid type class in C++. Here I am giving a working example of what I have devised so far. ...
6
votes
1answer
238 views

Fake duck typing with dynamic

There are sometimes situations where you have a couple of related classes with static fields or properties but you cannot access them via ...
1
vote
1answer
34 views

Generic comparitive array selection sort

My code works, but my IDE is giving me warnings for unchecked method invocation. I have found useful information about Comparable arrays here. I have found useful information about unchecked method ...
1
vote
1answer
84 views

Custom observable types and their supporting classes

I decided that for some parts of my project, communication through events would be very handy, for that purpose I started writing the most basic part of the event system, an interface consisting of ...
2
votes
0answers
97 views

Object pooling in WPF

In a WPF project I'm working on, often multiple objects reuse the same AnimationTimeline, to smooth that out I made an ...
4
votes
1answer
370 views

Generic message system using variadic templates

in my spare time I´m creating a hobby game engine as decided to write some of my systems on my own. As the time passes I´ve decided to start publishing it as a independent libraries for use (so ...
-3
votes
1answer
75 views

Using Generics in C# [closed]

I am curious about Generics in C# and would like to know your opinion do I correctly use Generics about how to improve this code For example, I have a payment system of some shop. So I have ...
2
votes
1answer
86 views

Event based input files management system

I'm currently making a system that can accept different sorts of files and some classes are interested only in specific types of files, while some don't discriminate at all. Note Type of file isn't ...
0
votes
0answers
45 views

Type-safe two-step computational pipelines

I have several "computation pipelines" that share the same purpose and number of steps, even if the step implementations and the classes of the the intermediate values that are passed between them are ...
7
votes
5answers
2k 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 ...
2
votes
0answers
393 views

Processor for handling generic commands

I'm trying to implement business logic layer based on concepts of commands and command handlers. A command is a thing that contains input parameters for executing some action, and it knows what kind ...