Skip to content

Instantly share code, notes, and snippets.

View tkokof's full-sized avatar

Hugoyu tkokof

View GitHub Profile
// desc eval arithmetic
// note improve error handling
// maintainer hugoyu
using System;
using System.Diagnostics;
using System.Collections.Generic;
public class EvalArithmetic
{
@tkokof
tkokof / SortedList.cs
Created July 26, 2018 12:16
simple sorted list implementation using insert sort
// simple sorted list implementation using insert sort
// maintainer hugoyu
using System.Collections.Generic;
namespace Util
{
public class SortedList<T>
{
public SortedList(IComparer<T> comparer = null)
// desc simple calculator constrains implementation
// note codes(adjusted) from https://www.codeproject.com/Articles/33617/Arithmetic-in-Generic-Classes-in-C
// maintainer hugoyu
using System;
/// <summary>
/// This interface defines all of the operations that can be done in generic classes
/// These operations can be assigned to operators in class Number<T>
/// </summary>
// desc simple implementation of matrix
// maintainer hugoyu
#ifndef __matrix_h__
#define __matrix_h__
#include <cassert>
#include <cstring> // memset
#include <memory>
// desc simple implementation of sparse matrix
// maintainer hugoyu
#ifndef __sparse_matrix_h__
#define __sparse_matrix_h__
#include <cassert>
#include <string>
#include "common.h"
public static class Sample
{
static int gsN = 127; // N(N+1)/2 = 8128 < 2^{13}
static float gsB = 2 * gsN + 1;
static float gsB2 = gsB * gsB;
static float gsFactor = (gsN - 1) * Mathf.Sqrt(0.5f);
static float gsInvFactor = 1.0f / gsFactor;
public static ushort CompressNormal(Vector3 normal)
{
using System.Diagnostics;
public interface ITuple
{
int Length
{
get;
}
object this[int index]
@tkokof
tkokof / RLE.cs
Last active January 3, 2020 07:25
simple RLE implementation
using System;
using System.Collections.Generic;
public static class RLE
{
public const byte ESCAPE = 92; // '\'
public const byte MAX_DUPLICATE_COUNT = byte.MaxValue;
public static byte[] Compress(byte[] input)
{
@tkokof
tkokof / LCS.cs
Created February 1, 2019 09:05
Longest Common Subsequence
using System;
using System.Text;
using System.Collections.Generic;
public static class LCS
{
struct LCSInfo
{
public int Len;
public int BackType;
@tkokof
tkokof / Heap.cs
Created February 2, 2019 12:40
generic heap implementation
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Heap<T> where T : IEquatable<T>
{
public static Heap<T> Build(IEnumerable<T> items, Func<T, T, bool> predicate)
{
var heap = new Heap<T>(predicate);