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
1answer
13 views
Generic Int conversion to scalar
I'm new to Scala and I'm trying to write a generic function to convert from Int to any scalar.
For example:
...
8
votes
3answers
442 views
Return a key when a function returns true
I've no idea what to call this, so I called it Classify since that's how I use it.
Basically, the idea is to pass a ...
1
vote
2answers
61 views
Alternative to using Object and casting in a map
I have the following class which represents a set of properties.
...
7
votes
1answer
65 views
Database abstraction layer for multiple providers
There's been a lot of questions lately about database provider and repository design especially without entity framework or alike.
I thought I try myself to create a reusable framework for this kind ...
3
votes
2answers
59 views
C# enumerable property like .Any that accounts for nulls
Brief Description:
A generic extension method that performs the same function as IEnumerable.Any(), but does not throw an error when passed a parameter with a <...
7
votes
1answer
64 views
Sum numbers input from terminal
The following Golang code accepts a sequence of numbers (any integer and float type) in the terminal, adds them, and prints the result (sum) to the terminal.
Actually in Golang you can't add ...
9
votes
2answers
408 views
Responding to API requests with much complexity
So having used the SE API multiple times, I like how all responses are in a Wrapper object, and for my own API design I figured it was a good method to follow.
Of ...
7
votes
1answer
79 views
HTML-rendering framework for emails
Sometimes I need to auto-generate html-emails. To make this task a little bit easier I created a simple framework that takes care of rendering HTML. Because I'm mainly interested in generating HTML ...
10
votes
3answers
188 views
Structure to ByteArray Extension
I have a need to turn various structures into byte arrays to be sent over serial port to another machine. I created generic extensions to turn any structure into a byte array and from a byte array ...
1
vote
0answers
30 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 ...
8
votes
5answers
127 views
Removing exact instances of elements in one list from another
Basically, here's the problem statement:
Given an IEnumerable<T> source and an IEnumerable<T> exceptions, return ...
3
votes
1answer
148 views
A small generic array in C
The generic arrays in C I found on the net used either of these methods:
The preprocesser with #define and #include (a lot of ...
2
votes
2answers
51 views
Data structure to store large numbers of runtime-dependent arithmetic types
Warning: lots of code. If it's too much, please focus primarly on channel.h and channel.hpp.
This is my first time posting on ...
4
votes
2answers
86 views
On-line evaluation of mean and variance in C#
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
350 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).
<...
3
votes
1answer
96 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
133 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
80 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
99 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
43 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
107 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
167 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
55 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
95 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
91 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
81 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
127 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
122 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
149 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
403 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
175 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
70 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
77 views
Object factory from interface types
I have a library that defines a bunch of ISprite interfaces, like IPieceSprite and ...
2
votes
1answer
124 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
44 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
46 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
73 views
Optimize OrderBy Generic Method
Here is my OrderBy method which includes concatenated column names.
Can this be achieved more efficiently?
...
1
vote
0answers
46 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....
1
vote
1answer
58 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. I'...
1
vote
1answer
69 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
81 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
211 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
105 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
877 views
3
votes
1answer
63 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
85 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
373 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
46 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
1k views
Type to byte array conversion in Swift
I need the byte representation of a given type, especially double, float, int8, etc.
...