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
3answers
110 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
2
votes
1answer
87 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 ...
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. ...
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 ...
27
votes
0answers
836 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
4
votes
0answers
216 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
4
votes
0answers
122 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 ...
4
votes
0answers
99 views

Implementing insertAt for both [a] and [(i,a)] lists

I've implemented generic insertAt function which inserts element into both indexed and ...
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
0answers
126 views

Extendable REST-Client - follow-up

My previous RestClient wasn't disposing a lot of resources. I've fixed it (hopefully without introducing new issues) and because a few new patterns emerged I did a ...
3
votes
0answers
186 views

Generic Factory using Function library

Here's my implementation of Generic Factory using Function library. It was created using Function library because I understand that the newInstance method is ...
3
votes
0answers
1k views

Generic wrapper for Alamofire Request's function jsonResponse wrapper

I am trying to wrap a responseJSON function of a Request class of Alamofire because when I send an API request I get a response ...
3
votes
0answers
72 views

Advice on modelling with generics in Java

Use Case The third party library that I am working with implements its data model in this fashion. ...
2
votes
0answers
50 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
0answers
116 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 ...
2
votes
0answers
601 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 ...
2
votes
0answers
25 views

Unification with sequence variables and flexible arity functions

Today I wrote an implementation of the unification algorithm found in Temur Kutsia's 2002 paper. I didn't just do this for fun, it's related to other research I'm doing. I'm feeling more confident in ...
2
votes
0answers
155 views

Generic Unrolled Linked List with IList<T> interface implementation

I was inspired by the Phillip Trelford "Beyond Lists" presentation published on InfoQ. So, I decided to make it simple, yet still capable to act as IList<T>. ...
2
votes
0answers
264 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 inner-...
2
votes
0answers
102 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 ...
2
votes
0answers
232 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 ...
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 ...
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 ...
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 ...
1
vote
0answers
498 views

C# MVC Generic Custom Model Binder

I recently created a custom model binder as a training exercise and wanted to see how I could improve it. It currently uses recursion and works great, but I was wondering how I could convert this to ...
1
vote
0answers
211 views

Generic natural merge sort a linked-list in C

I have a .h file that implements my "generic" by defining LINK_* beforehand. This is an implementation of natural merge sort on doubly-linked lists using log n ...
1
vote
0answers
274 views

Refactoring duplicate custom service configuration in .NET core

In my current .NET Core project, I want to inject two services into my controllers for dependency injection. I wrote the following extension methods that each takes a ...
1
vote
0answers
43 views

Caching generic types statically

Given the need to share several big models throughout an application (web application, the models need to persist between requests), I would like to create a unified cache handler to keep them in ...
1
vote
0answers
428 views

Generic Pairing Heap Performance

I have made a generic pairing heap library in C. Pairing heaps are one of the several heap variants with better asymptotic running times than standard binary heaps (others include Fibonacci heaps and ...
1
vote
0answers
222 views

.NET List Serializer design

A few weeks back I wrote a class to help serialize/deserialize objects file. The file format requested was json, then compressed. After some coding/testing I settled on this design: ...
1
vote
0answers
100 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 heap....
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 ...
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. ...