Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
:- use_module(library(chr)). | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% This program performs conversions from | |
% regex -> NFA -> DFA | |
% | |
% It consists of three parts: | |
% 1. A regular expression parser (DCG) | |
% 2. A CHR program for converting DCG parse tree to an NFA | |
% 3. A CHR program for converting the NFA to a DFA |
// ============================================================================ | |
// gzstream, C++ iostream classes wrapping the zlib compression library. | |
// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner | |
// | |
// This library is free software; you can redistribute it and/or | |
// modify it under the terms of the GNU Lesser General Public | |
// License as published by the Free Software Foundation; either | |
// version 2.1 of the License, or (at your option) any later version. | |
// | |
// This library is distributed in the hope that it will be useful, |
# Makefile template for a shared library in C | |
# https://www.topbug.net/blog/2019/10/28/makefile-template-for-a-shared-library-in-c-with-explanations/ | |
CC = gcc # C compiler | |
CFLAGS = -fPIC -Wall -Wextra -O2 -g # C flags | |
LDFLAGS = -shared # linking flags | |
RM = rm -f # rm command | |
TARGET_LIB = libtarget.so # target lib | |
SRCS = main.c src1.c src2.c # source files |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
/***************************************************************************** | |
* QuantCup 1: Price-Time Matching Engine | |
* | |
* Submitted by: voyager | |
* | |
* Design Overview: | |
* In this implementation, the limit order book is represented using | |
* a flat linear array (pricePoints), indexed by the numeric price value. | |
* Each entry in this array corresponds to a specific price point and holds | |
* an instance of struct pricePoint. This data structure maintains a list |
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
local ffi = require("ffi") | |
ffi.cdef[[ | |
typedef void (*cb)(void); | |
void call(int n, void (*)(void)); | |
void loop(int n); | |
void func(void); | |
]] | |
local callback = ffi.load("./callback.so") | |
local timeit = require("timeit") |
rsync (Everyone seems to like -z, but it is much slower for me)