All Projects → somethingnew2-0 → go-erasure

somethingnew2-0 / go-erasure

Licence: MIT license
Erasure coding (Reed–Solomon coding) in Go

Programming Languages

c
50402 projects - #5 most used programming language
go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to go-erasure

ParPar
High performance PAR2 create client for NodeJS
Stars: ✭ 110 (+150%)
Mutual labels:  reed-solomon, reedsolomon
blockyarchive
Blocky archive - multithreaded archiver offering bit rot protection and sector level recoverability
Stars: ✭ 88 (+100%)
Mutual labels:  reed-solomon, reedsolomon
reed-solomon-erasure
[Looking for new owners/maintainers, see #88] Rust implementation of Reed-Solomon erasure coding
Stars: ✭ 135 (+206.82%)
Mutual labels:  reed-solomon, erasure-coding
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (+304.55%)
Mutual labels:  trie
Patricia
Garbage collector-sensitive patricia tree for IP/CIDR tagging
Stars: ✭ 194 (+340.91%)
Mutual labels:  trie
Opencc4j
🇨🇳Open Chinese Convert is an opensource project for conversion between Traditional Chinese and Simplified Chinese.(java 中文繁简体转换)
Stars: ✭ 187 (+325%)
Mutual labels:  trie
Router
⚡️ A lightning fast HTTP router
Stars: ✭ 158 (+259.09%)
Mutual labels:  trie
csharp-trie
A trie (prefix tree) data structure implementation in C#.
Stars: ✭ 30 (-31.82%)
Mutual labels:  trie
trie
My take on an efficient implementation of a Trie in Javascript
Stars: ✭ 72 (+63.64%)
Mutual labels:  trie
Algorithms-Java
A collection of common algorithms and data structures implemented in Java.
Stars: ✭ 141 (+220.45%)
Mutual labels:  trie
trie-perf
Performance shootout of various trie implementations
Stars: ✭ 18 (-59.09%)
Mutual labels:  trie
Data Structures
A collection of powerful data structures
Stars: ✭ 2,534 (+5659.09%)
Mutual labels:  trie
rust sequence trie
Ergonomic trie data structure
Stars: ✭ 22 (-50%)
Mutual labels:  trie
unitdb
Fast specialized time-series database for IoT, real-time internet connected devices and AI analytics.
Stars: ✭ 97 (+120.45%)
Mutual labels:  trie
goblin
A golang http router based on trie tree.
Stars: ✭ 52 (+18.18%)
Mutual labels:  trie
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (+277.27%)
Mutual labels:  trie
trie
Trie (a.k.a. prefix tree) C# implementation. Has constant-time string prefix lookup.
Stars: ✭ 84 (+90.91%)
Mutual labels:  trie
galois
A performant NumPy extension for Galois fields and their applications
Stars: ✭ 106 (+140.91%)
Mutual labels:  reed-solomon
trie-mux
A minimal and powerful trie based url path router (or mux) for Go.
Stars: ✭ 25 (-43.18%)
Mutual labels:  trie
lexpy
Python package for lexicon; Trie and DAWG implementation.
Stars: ✭ 47 (+6.82%)
Mutual labels:  trie

go-erasure Build Status Coverage Status

Disclaimer: I recommend the klauspost/reedsolomon erasure coding library over this one as it is more performant and has better support for multiple architectures.

Go bindings for erasure coding (Reed-Solomon coding).

Erasure coding is similar to RAID based parity encoding, but is more generalized and powerful. When defining an erasure code, you specify a k and m variable. m is the number of shards you wish to encode and k is the number shards it takes to recreate your original data. Hence k must be less than m and usually not equal (as that would be a pointless encoding). The real magic with erasure coding is that fact that ANY k of the m shards can recreate the original data. For example, a erasure coding scheme of k=8 and m=12 means any four of the encoded shards can be lost while the original data can still be constructed from the valid remaining eight shards.

This library is aimed at simplicity and performance. It only has three methods including a constructor which are all thread-safe! Internally it uses Cgo to utilize a complex C library. For a more in-depth look into this library be sure to check out the Intel® Storage Acceleration Library and especially their corresponding video. One feature it does add is an optimization for decoding. Since there are m choose k possible inverse matrices for decoding, this library caches them (via lazy-loading) so as reduce the amount of time decoding. It does so by utilizing a trie where the sorted error list of shards is the key to the trie and the corresponding decode matrix is the value.

I hope you find it useful and pull requests are welcome!

Usage

See the GoDoc for an API reference

Encode and decode random data

package main

import (
  "bytes"
  "log"
  "math/rand"
  
  "github.com/somethingnew2-0/go-erasure"
)

func corrupt(source, errList []byte, shardLength int) []byte {
	corrupted := make([]byte, len(source))
	copy(corrupted, source)
	for _, err := range errList {
		for i := 0; i < shardLength; i++ {
			corrupted[int(err)*shardLength+i] = 0x00
		}
	}
	return corrupted
}

func main() {
	m := 12
	k := 8
	shardLength := 16 // Length of a shard
	size := k * shardLength // Length of the data blob to encode

	code := erasure.NewCode(m, k, size)

	source := make([]byte, size)
	for i := range source {
		source[i] = byte(rand.Int63() & 0xff) //0x62
	}

	encoded := code.Encode(source)

	errList := []byte{0, 2, 3, 4}

	corrupted := corrupt(append(source, encoded...), errList, shardLength)

	recovered := code.Decode(corrupted, errList, true)

	if !bytes.Equal(source, recovered) {
		log.Fatal("Source was not sucessfully recovered with 4 errors")
	}
}

Development

To start run source dev.sh or more simply . dev.sh to setup the git hooks and GOPATH for this project.

Run go test or go test -bench . to test the unit tests and benchmark tests.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].