Skip to content

Instantly share code, notes, and snippets.

@mookerji
mookerji / rocksdb.clj
Last active March 5, 2020 10:12
Idiomatic Clojure bindings for the C++ RocksDB library, an embedded persistent key-value store for flash storage and server workloads based on LevelDB. This implementation is based partially on Factual's clj-leveldb and is up here for some early review. If I've shared it with you, please don't repost until merged into a public Github.
(ns org.flausenhaus.rocksdb
"Idiomatic Clojure bindings for the C++ RocksDB library, an embedded
persistent key-value store for flash storage and server workloads based on
LevelDB. More details about RocksDB are given at
https://github.com/facebook/rocksdb/wiki/Rocksdb-Architecture-Guide.
The implementation here borrows heavily from Factual's clj-leveldb.
This namespace provides a few things:
0. Protocols/type definitions: byte serialization (IByteSerializable),
closeable sequences (CloseableSeq), and mutable
; .emacs file
; Bhaskar Mookerji
;
; Started: Sunday, 3 October 2010
;;;
;;; Static configuration stuff
;;;
(winner-mode 1)
@mookerji
mookerji / ConcurrentLRUCache.java
Created October 10, 2013 17:13
Concurrent write-order FIFO for caching: The cache uses a ConcurrentHashMap and a ConcurrentLinkedQueue; and atomic integers for timestamping accesses, writes, and the queue size. The map maintains the cached values, and the queue maintains an ordering of the elements in write-FIFO order. ConcurrentLRUCaches eschews locks in favor of lock-free d…
package memoizer;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
public class ConcurrentLRUCache {
private final int kCacheSize;
private final ConcurrentHashMap<Object, CachedValue> mMap;
@mookerji
mookerji / YCMemoizer.java
Created October 8, 2013 23:02
Issue of the day: If you're using purely Java (or heaven forbid, C++), how do you *generically* memoize/cache values for functions that make recursive function calls? Reflection or runtime-method dispatch is probably pretty messy. It seems an actual Y-Combinator is *great* for this.
package memoizer;
import memoizer.ConcurrentLRUCache;
class YCMemoizer {
interface F<R, A> {
R apply(A n);
}
interface F_F<R, A> {