Skip to content

Instantly share code, notes, and snippets.

Eugene Zatepyakin inspirit

View GitHub Profile
@inspirit
inspirit / lfstack_dcas.hpp
Created Jun 20, 2015
Lock-free Stack using Double width CAS and Packed/Tagged pointer (based on Go)
View lfstack_dcas.hpp
#pragma once
#include <atomic>
#include <type_traits>
template<typename T, size_t Capacity>
struct lfstack {
struct node_t final {
T value;
node_t *next;
View gist:a14b0a1f227a2d288b46
// we only allow no more than 8 worker in pool
std::atomic_uint_fast8_t idle_mask = {0};
// this function is called by each thread when it is about to sleep
void register_idle(const size_t thread_id)
{
idle_mask.fetch_or(1u << thread_id, std::memory_order_release);
}
// this function can be called from anywhere at anytime
@inspirit
inspirit / LinkedBlockingQueue.h
Created Jun 12, 2015
Objective-C LinkedBlockingQueue
View LinkedBlockingQueue.h
#import <Foundation/Foundation.h>
@interface LinkedBlockingQueue : NSObject
{
// NOP
}
@property(nonatomic, readonly) NSUInteger count;
@property(nonatomic, readonly) NSUInteger freeCount;
@inspirit
inspirit / Convolution.hpp
Created Oct 2, 2013
Separable Convolution and Gaussian Blur
View Convolution.hpp
#pragma once
#ifndef CONVOLUTION_H_INCLUDED
#define CONVOLUTION_H_INCLUDED
/**
* Separable Convolution routines with SSE and NEON intrinsics
*
* this implementation is based on OpenCV Filter Class
* with template optimizations and SIMD intrinsic
*
@inspirit
inspirit / cholesky
Created Oct 24, 2012
Cholesky solver using simple math only
View cholesky
function cholesky_solve(A:Vector.<Number>, size:int, b:Vector.<Number>):Boolean
{
var col:int, row:int, col2:int;
var val:Number;
for (col = 0; col < size; ++col)
{
var inv_diag:Number = 1;
var cs:int = (col * size);
var rs:int = cs;
@inspirit
inspirit / box_blur_noscale.c
Created Oct 11, 2012
Const time box blur (no scale version)
View box_blur_noscale.c
void box_blur_noscale(const uint8_t* input, int32_t* out, const int w, const int h, int hwin)
{
const int win = 2*hwin+1;
int *_buf = (int*)alloca((w*win+w) * sizeof(int));
int* sums = _buf + w*win;
int* next_row = _buf;
int* oldest_row = _buf;
int i, j;
memset(sums, 0, w*sizeof(int));
@inspirit
inspirit / RNDMarsaglia.as
Created Jun 24, 2011
A 32-bit random number generator by George Marsaglia
View RNDMarsaglia.as
var __x:uint = 123456789;
var __y:uint = 362436069;
var __z:uint = 21288629;
var __w:uint = 14921776;
var __c:uint = 0;
function rnd():uint
{
__x = __x + 545925293;
__y = __y ^ (__y<<13);
@inspirit
inspirit / LUSolveMxN.as
Created Jun 21, 2011
Solve MxN system using LU Decomposition
View LUSolveMxN.as
/**
* LU decomposition/solve is used for NxN (square) matrices
* but using additional computations we can use LU decomposition
* to solve MxN system (since LU routines less computation expensive)
*/
// u can find LU and MatrixMath Classes at my Google repo
var lu:LU = new LU();
@inspirit
inspirit / LList.as
Created Jun 19, 2011
Fast & Simple Dual Linked List
View LList.as
package ru.inspirit.asfeat.struct
{
/**
* Simple but fast Dual Linked List approach
* Core implementation idea grabbed from Linux Kernel C source
*
* @author Eugene Zatepyakin
*/
public final class LList
{
@inspirit
inspirit / HomographyDecomposition.as
Created Dec 14, 2010
Decompose Homography into Rotation matrix & Translation vector
View HomographyDecomposition.as
var intrinsic:Vector.<Number> = new Vector.<Number>(9, true);
var intrinsicInverse:Vector.<Number> = new Vector.<Number>(9, true);
var R:Vector.<Number> = new Vector.<Number>( 9, true );
var t:Vector.<Number> = new Vector.<Number>( 3, true );
// SVD routine
var svd:SVD = new SVD();
// input homography[9] - 3x3 Matrix
You can’t perform that action at this time.