Skip to content

Instantly share code, notes, and snippets.

View pacuna's full-sized avatar

Pablo Acuña pacuna

  • Spotify
  • Austin, TX
View GitHub Profile
package simplelist
import "testing"
func Test_List(t *testing.T) {
l := New()
l.Add([]byte("item1"))
l.Add([]byte("item2"))
if l.Size() != 2 {
package main
import (
"fmt"
"sortedlist/simplelist"
"sync"
)
func main() {
l := simplelist.New()
type list struct {
mu sync.Mutex
head *node
size int
}
func (l *list) Add(item []byte) bool {
var pred, curr *node
key, _ := hashstructure.Hash(item, nil)
l.mu.Lock()
defer l.mu.Unlock()
pred = l.head
curr = pred.next
for curr.key < key {
package main
import (
"fmt"
"sortedlist/coarselist"
"sync"
)
func main() {
l := coarselist.New()
type node struct {
mu sync.Mutex
item []byte
key uint64
next *node
}
func (n *node) lock() {
n.mu.Lock()
}
func (l *list) Add(item []byte) bool {
key, _ := hashstructure.Hash(item, nil)
l.head.lock()
pred := l.head
curr := pred.next
curr.lock()
// Displace locks during each iteration.
// We keep the lock for curr when unlocking pred.
func (l *list) Remove(item []byte) bool {
key, _ := hashstructure.Hash(item, nil)
l.head.lock()
pred := l.head
curr := pred.next
curr.lock()
for curr.key < key {
pred.unlock()
@pacuna
pacuna / sqlite_table_valued.py
Last active October 3, 2020 23:20
Implementing SQLite UDFs and table-valued functions in Python
from peewee import *
from playhouse.sqlite_ext import TableFunction
import json
# https://github.com/coleifer/peewee/
# Basic connection and sql execution
db = SqliteDatabase('foo.db')
db.connect()
db.execute_sql(
"CREATE TABLE IF NOT EXISTS pageAds (pageid STRING, adid_list JSON);")
@pacuna
pacuna / skiplist.go
Created October 3, 2020 23:17
SkipList in Go (from original paper)
// Implementation of a SkipList using the original paper's algorithm:
// https://15721.courses.cs.cmu.edu/spring2018/papers/08-oltpindexes1/pugh-skiplists-cacm1990.pdf
//
// Example usage:
// sl := db.NewSkipList()
// sl.Insert([]byte("foo"), []byte("bar"))
// sl.Insert([]byte("foo"), []byte("world"))
// fmt.Println(string(sl.Search([]byte("foo"))))
//
package db