Skip to content

Instantly share code, notes, and snippets.

View tkokof's full-sized avatar

Hugoyu tkokof

View GitHub Profile
@tkokof
tkokof / big_int.lua
Created January 4, 2022 13:15
big int add & mul
-- desc big int add & mul
-- maintainer hugoyu
local big_int = {}
local min_add_digit_num = 9
local min_mul_digit_num = 5
local function digit_num(v)
return #tostring(v)
@tkokof
tkokof / reload_module_simple.lua
Created April 9, 2019 08:23
a simple reload module implementation of Lua
local function try_get_upvalue(func, name)
local upvalue_index = 1
while true do
local u_name, u_value = debug.getupvalue(func, upvalue_index)
if not u_name then
break
elseif u_name == name then
return u_name, u_value, upvalue_index
end
upvalue_index = upvalue_index + 1
@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);
@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 / 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)
{
using System.Diagnostics;
public interface ITuple
{
int Length
{
get;
}
object this[int index]
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)
{
// desc simple implementation of sparse matrix
// maintainer hugoyu
#ifndef __sparse_matrix_h__
#define __sparse_matrix_h__
#include <cassert>
#include <string>
#include "common.h"
// desc simple implementation of matrix
// maintainer hugoyu
#ifndef __matrix_h__
#define __matrix_h__
#include <cassert>
#include <cstring> // memset
#include <memory>
// 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>