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.
0
votes
0answers
14 views
On-line evaluation of mean and variance
In various projects, I have to evaluate the mean and/or the variance of relatively large samples.
I wrote the following, to help me evaluate these quantities with a constant footprint. Basically, it ...
4
votes
2answers
284 views
Generic binary tree in C#
This is a simple implementation of a generic binary tree that holds elements of type T. I was wondering if there was something that could be done better (especially in the EnumerateNodes methods).
...
2
votes
0answers
21 views
User defined filters for derived object properties
I have created the BasicSetting class with two properties: Name & Value. The user is ...
3
votes
1answer
85 views
Recursive flattening of Swift sequences - an overly complicated approach
I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
6
votes
3answers
113 views
Generic graph implementation in C#
I am implementing fundamental data structures in C# while trying to learn techniques in the language to make my code cleaner, more concise, and reusable. I have implemented a generic graph with a few ...
6
votes
2answers
59 views
Implement a generic Fibonacci sequence in Rust without using Copy trait
I'm trying to learn Rust and am a beginner. How does one go about implementing a generic version of the Fibonacci sequence without using Copy trait in Rust? My code ...
6
votes
2answers
89 views
Django controller method to list the top characters, guilds, and killers
I've been reading the Chapter 8 of this book.
Here's the view I'm currently coding. It list all characters/guilds according to the type of URL.
...
1
vote
0answers
29 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:
...
3
votes
2answers
94 views
Avoiding misuse of optional unwrapping: LinkedList
Below is my implementation of a generic linked list in swift. Unfortunately, Swift playgrounds won't run until the compiler is totally happy - often, that involves clang making me explicitly unwrap ...
2
votes
0answers
22 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 ...
1
vote
2answers
114 views
Intersect two ranges in Swift
Can you think of a reason the following extension should not be used in production, or a better way of implementing it:
...
2
votes
0answers
45 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>.
...
1
vote
1answer
74 views
Simple type-safe and thread-safe Rust event system
I'm creating a relatively simple type-safe and thread-safe Rust event system. It is to be used with and within an IRC library I'm making, but should work just fine for other use-cases. It needs to be ...
5
votes
2answers
90 views
Indexed Property implementation
I have a class that encapsulates a PowerShell Runspace object which, among many other things, has methods for getting and setting variables in the session state. ...
1
vote
1answer
80 views
Using T type parameter to clone a collection
I want to clone a collection with the following method and I want to know if it can be optimized:
...
3
votes
1answer
109 views
Fixed-length Sequences in Swift 2.2
The following is an implementation of fixed-length sequences that makes very exotic (and hopefully fun) use of Swift 2.2 types. The question is what exactly is the cost of having the type checker ...
3
votes
0answers
108 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 ...
5
votes
2answers
105 views
A more generic `DelegateCommand`
In an effort to create ever-improving code, I've written a DelegateCommand that takes a generic type parameter to be acted upon. It's pretty trivial, so it should ...
2
votes
3answers
385 views
Generic methods to find the maximal element in part of a list
This is the question from Oracle docs:
Write a generic method to find the maximal element in the range
[begin, end) of a list.
I had my implementation like this:
...
1
vote
2answers
126 views
Fixed-length Stack in Java
I implemented a fixed-length stack in Java for use in my fractal generator program, an RPN calculator and my esolang interpreter. This is a generic stack, and goes over and above the call of duty in ...
3
votes
2answers
68 views
Custom key class for .NET 3.5 framework
I use .NET 3.5 framework, so no tuples. I have many use cases where I have to create a custom key for a dictionary. How can I make this better?
...
5
votes
1answer
68 views
Object factory from interface types
I have a library that defines a bunch of ISprite interfaces, like IPieceSprite and ...
2
votes
1answer
106 views
Java Tree Implementation
I wrote a simple tree data type in Java consisting of nodes which are themselves trees, and where each tree has its own list of children (not a binary tree). I plan on eventually using it in a minimax ...
1
vote
1answer
42 views
Single Flag Only Enum (RestrictedEnum<T>)
This class simply allows you to use an enum while only allowing you to set a single flag. If multiple flags are set they will be rejected--unless the total of the combined flags is the same value of ...
4
votes
1answer
38 views
Matasano cryptopals: Conversion to base 64 (with generic types)
My main interest is in how I have handled the generics and if it's idiomatic. I want the user to be able to specify what kind of integer type they would like to use for the encoding (u8, u16, u32, ...
2
votes
1answer
68 views
Optimize OrderBy Generic Method
Here is my OrderBy method which includes concatenated column names.
Can this be achieved more efficiently?
...
1
vote
0answers
44 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
53 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
63 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
78 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 ...
2
votes
1answer
131 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
91 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
626 views
3
votes
1answer
54 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 ...
2
votes
1answer
68 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
229 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
45 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 ...
6
votes
2answers
866 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
801 views
Give me thy name, I'll invoke thee
This generic function invokes a property of a given object by name:
...
-3
votes
1answer
82 views
2
votes
0answers
60 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
124 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 ...
2
votes
0answers
75 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
170 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
288 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 ...
1
vote
1answer
48 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
134 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
55 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
1k 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 ...