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.

learn more… | top users | synonyms

1
vote
0answers
39 views

Generic implementation of mutable binary heap

std::priority_queue does not support dynamically updating element priorities. This class template extends it by allowing updating priorities of elements in the ...
1
vote
1answer
36 views

Generic implementation of SiftUp/Down operations on binary heap

Binary heap construction and maintenance boil down to the two basic operations: sift up and sift down. Following are generic template implementations of the two operations. Any comments are welcome. ...
1
vote
1answer
51 views

Templated linked list in Java

I recently reviewed some data structure concepts, so I implemented my own templated linked list. I am very interested about the code efficient and performance. ...
3
votes
1answer
64 views

Creating a lightweight strongly-typed parameter infrastructure

I'm looking for some feedback on some code, designed to allow me to strongly-type parameters, which get passed to functions. I'm only really looking for comments on making my parameters more strongly ...
1
vote
1answer
40 views

A Dynamic CSV Serializer

I made a dynamic CSV serializer as a learning challenge a while back, I'm hoping to get my code picked apart so I can learn what I can do better. This is a bit long, so I wouldn't expect anyone to ...
4
votes
2answers
81 views

Dictionary lookup of non-nullable struct into nullable destination

I've got an IDictionary<SomeT, DateTime> that does not always contain the desired key-value pair. For that reason, a target method expects a ...
12
votes
2answers
335 views

Extension method to list enum values

I have the following enum extension method: ...
3
votes
1answer
33 views

Generic Object Editing Classes with Controller, ViewModelProvider and DBUpdater

I am beginning to use generics and would like feedback on the following set of classes that will serve as the basis for an app that contains a large number of basic CRUD-y entities. I have used ...
3
votes
1answer
35 views

Ignore nil values and unwrap optionals returning the value as the wrapped type

My primary concern is that this has been written as a global function. I think it would be better if this was a function of the SignalProducer class but I am not ...
11
votes
3answers
107 views

Poor man's lazy evaluation in Java 8

I have an class that cheaply imitates a lazy evaluation scheme. The class is for representing a file and additionally providing meta data on the file. Some of the meta-data can be expensive to ...
4
votes
0answers
33 views

Heap update generic algorithms

In the standard library, there are no algorithms for element updates. This makes it unsuitable as a queue for a Dijkstra's algorithm, for example. Thus I implemented generic heap update functions with ...
5
votes
1answer
125 views

Type to byte array conversion in Swift

I need the byte representation of a given type, especially double, float, int8, etc. ...
11
votes
3answers
787 views

Give me thy name, I'll invoke thee

This generic function invokes a property of a given object by name: ...
-2
votes
1answer
78 views

How to use generic [closed]

I have function that builds different types of boxes. ...
2
votes
0answers
30 views

Multi class-type Object pool based on Libgdx Pool

I've done some code so you can obtain Object of any Class from Pool, take a look at it, is it safe? At least it works. MultiPool class has method obtain with Class param, so can know from which ...
5
votes
3answers
106 views

EventList<T> a generic list implementation that raises events when items are added and removed

I created this class for a project when I wanted to have List<T> properties on a class and also listen for items being added and removed. I looked at using ...
1
vote
0answers
59 views

Parsing JSON with generics

I get back two dictionaries, I need to parse through them and put in an array two objects. I think I did a very poor job and I have a feeling there is a better way to make the code more compact and ...
3
votes
2answers
150 views

Mutating Objects: Mutable<T> class

Recently I felt the need to write a Mutable<T> class so that I can pass immutable objects through methods, whose value can then be changed. Some examples of ...
5
votes
1answer
257 views

Generic method for obtaining enum items in an ushort object

The idea is to perform a bit-wise scan of an ushort provided to find any and all matches within an enum collection. The code I ...
2
votes
1answer
39 views

Dynamic CSV Formatter

I made a dynamic CSV formatter as a personal challenge after having to hardcode a behavior to convert some data to CSV earlier. You input any List that contains supported types as properties (all ...
0
votes
1answer
66 views

Fixed Point Number to String

I recently learned about using fixed point arithmetic on embedded systems without floating point hardware, so I decided to code it. I tried to write in good style, but emphasized speed over style. ...
1
vote
0answers
50 views

Better way to deep copy than this? How can I make it generic by `Collection` type?

Could I make this method for deep copy generic to the Collection type? That method is so simple and I can't imagine ever needing to change it, so maybe I should ...
8
votes
3answers
980 views

Simple generic double buffer pattern

I wrote a small generic implementation of a simple generic double buffer pattern, and I was wondering if it's actually thread safe or can be improved in any way. Note: The specific part that I'm ...
-1
votes
1answer
57 views

WCF generic proxy caller

I have an ASP.NET web-client and many WCF services. I used it this way: ...
4
votes
3answers
199 views

Generic toString() for JPA base entity class

In a Java/JPA project I usually define a base class (on which I put the id). The goal is to implement an generic toString() on this base class (named BaseEntity) from which all other entities inherit. ...
3
votes
2answers
70 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
3
votes
2answers
87 views

Related classes around generic types

I'm wondering if this code can be simplified. I'm less than thrilled about the fact that I repeat the Draw method in both CatModel and DogModel. For that matter, I'm not real happy that that method is ...
5
votes
1answer
187 views

Early Binding with Generics

I have a class which takes the method address and arguments, and executes it later when told to do so. ...
1
vote
2answers
87 views

Implementing a generic class and choosing a collection based on a type

In this topic here I have aksed for help to sort out an error while creating a generic class whose method can return a different collection given a type. I received the answer and working solution but ...
8
votes
1answer
347 views

Generic domain independent Monte Carlo Tree Search methods library

I've written this small generic library for the purpose of my Bachelor's thesis. It's fully functional and unit tested and I want to get as many opinions as possible regarding overall code quality ...
3
votes
0answers
107 views

OOP paradigm implementation of a Dictionary data model

Here is the implementation of interface Dictionary using chained hash table class HashTableChained. Despite item 22* saying ...
4
votes
2answers
184 views

App settings helper

The helper should be able to set a default value if the value can't be fetched with the provided key. There is also a bool that will throw an error if the key value or the default value could not be ...
4
votes
1answer
205 views

Sorting a linked list using mergesort

This sorts a linked list using mergegort. Can you please critique my code and provide your thoughts on where I should improve my code? ...
0
votes
0answers
232 views

Generic method to pass lambda expressions performed on DTO's to Entity Framework

The following are generic methods that I use to perform lambda queries on DTO objects. The main method applies the expression to entities and returns DTO objects mapped from the entities (entities ...
7
votes
1answer
145 views

Efficient generic type conversion between numeric types in F#

It's easy to write a function that adds two ints in F#: let add x y = x + y Actually, it's the same as: ...
6
votes
3answers
360 views

Generic getting single value from DB in C#

Few months ago I posted my code Getting a single value from the DB. I implemented suggested changes and this is how it looks like right now: ...
4
votes
1answer
60 views

Generic Constraints and new()

I have have attempted to use generics and constraints to create functions that retrieve and save data from a number of similar objects. Each of these objects describe their own properties. When I use ...
5
votes
2answers
162 views

Recursively merge dictionaries with generic types in C#

I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
-1
votes
1answer
76 views

Singly linked list with generics and comparable data [closed]

I am currently reading about the thread-safe implementation of a linked list. Although I implemented this linked list while keeping in mind the issues from the first code review (Binary Tree). I would ...
2
votes
1answer
2k views

Cached-object Store c# with Redis client for persistent storage

I have written a Cached-Object store with a Redis Client for persistent storage. The application that is going to use this is a heavy read application with the occasional write. I assume that entire ...
1
vote
1answer
130 views

System to handle the short lived async task

I'm developing an application in which there are many short-lived tasks which are run in separate threads. I've developed a generic and reusable system to handle such a requirement. The code snippet ...
4
votes
1answer
59 views

Event driven timed I/O

The following code is used to access a shield which converts settings written over I2C to Servo output. I make use of the MRAA library since that's the default supported by my hardware. To prevent ...
6
votes
1answer
558 views

JSON serializer using generics rather than System.Object

I recently created a custom static class in C# to encode, hopefully, any object it is given (or collection of objects), because I was, at the time, unaware of a native C# library that did the same ...
1
vote
1answer
105 views

Initializing local variable to generic interface

Below is my working code written as an exercise in wildcards in generics and Java 8 type inference. My question will be about the commented line in union() method. ...
5
votes
2answers
57 views

Getting a set of subscribers from a subscriberMap

In my Java event bus project, I have a private generic method that retrieves a Set<Subscriber<E>> from a private ...
5
votes
2answers
581 views

Generic method to split provided collection into smaller collections

First time writing a generic method here. Input a List<T> and an int value and output a ...
6
votes
1answer
107 views

Java 8 unit test for third-party data feeds

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
10
votes
2answers
555 views

Optimize a generic foreach method that converts Datatable to my object using Reflection

I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
7
votes
4answers
395 views

Typed NSUserDefaults

I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to ...
0
votes
2answers
187 views

Implementation of peak finder

I implemented this peak finder for practice. I have tested it. Everything looks pretty good to me. Please let me know if there is any improvement I can make. Peak Finder Let input be an ...