aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-09-23 12:35:04 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-09-23 12:35:04 -0700
commit83cd586ea304d6f6aa190c65ee796baaba1941a7 (patch)
tree74bf8efcfb0a3d458767659d34ed3e58618f9d71
parent67c778d19c862218423a17f889401eaeb2ebfbb9 (diff)
feat: improved interface of map macro
-rw-r--r--.gitignore3
-rw-r--r--compile_commands.json424
-rw-r--r--include/libbio.h2
-rw-r--r--include/libn.h48
-rw-r--r--include/libn/macro/map.h64
-rw-r--r--rules.mk6
-rw-r--r--sys/cmd/cc/cc.c2
-rw-r--r--sys/cmd/cc/lex.c2
-rw-r--r--sys/libbio/fasta.c9
-rw-r--r--sys/libn/fs.c18
-rw-r--r--sys/libn/gz.c21
-rw-r--r--sys/libn/io.c28
-rw-r--r--sys/libn/memory.c10
-rw-r--r--sys/libn/random.c118
14 files changed, 568 insertions, 187 deletions
diff --git a/.gitignore b/.gitignore
index 8304f48..bb109a5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,10 +8,13 @@ test/
.build/
.test/
.cache/
+
include/libc
include/vendor
+
sys/cc
sys/nixos
+
bin/fasttree
bin/mafft
diff --git a/compile_commands.json b/compile_commands.json
index ee3e46a..1bf8db0 100644
--- a/compile_commands.json
+++ b/compile_commands.json
@@ -7,18 +7,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/bufio.o",
"-c",
- "sys/libn/bufio.c"
+ "-o",
+ ".build/sys/libn/error.o",
+ "sys/libn/error.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/bufio.c",
- "output": "/home/nolln/root/.build/sys/libn/bufio.o"
+ "file": "/home/nolln/root/sys/libn/error.c",
+ "output": "/home/nolln/root/.build/sys/libn/error.o"
},
{
"arguments": [
@@ -28,18 +29,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/arg.o",
"-c",
- "sys/libn/arg.c"
+ "-o",
+ ".build/sys/libn/bufio.o",
+ "sys/libn/bufio.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/arg.c",
- "output": "/home/nolln/root/.build/sys/libn/arg.o"
+ "file": "/home/nolln/root/sys/libn/bufio.c",
+ "output": "/home/nolln/root/.build/sys/libn/bufio.o"
},
{
"arguments": [
@@ -49,13 +51,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/coro.o",
- "-c",
"sys/libn/coro.c"
],
"directory": "/home/nolln/root",
@@ -70,18 +73,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/error.o",
"-c",
- "sys/libn/error.c"
+ "-o",
+ ".build/sys/libn/arg.o",
+ "sys/libn/arg.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/error.c",
- "output": "/home/nolln/root/.build/sys/libn/error.o"
+ "file": "/home/nolln/root/sys/libn/arg.c",
+ "output": "/home/nolln/root/.build/sys/libn/arg.o"
},
{
"arguments": [
@@ -91,13 +95,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/flate.o",
- "-c",
"sys/libn/flate.c"
],
"directory": "/home/nolln/root",
@@ -112,18 +117,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/fs.o",
"-c",
- "sys/libn/fs.c"
+ "-o",
+ ".build/sys/libn/gz.o",
+ "sys/libn/gz.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/fs.c",
- "output": "/home/nolln/root/.build/sys/libn/fs.o"
+ "file": "/home/nolln/root/sys/libn/gz.c",
+ "output": "/home/nolln/root/.build/sys/libn/gz.o"
},
{
"arguments": [
@@ -133,18 +139,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/gz.o",
"-c",
- "sys/libn/gz.c"
+ "-o",
+ ".build/sys/libn/fs.o",
+ "sys/libn/fs.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/gz.c",
- "output": "/home/nolln/root/.build/sys/libn/gz.o"
+ "file": "/home/nolln/root/sys/libn/fs.c",
+ "output": "/home/nolln/root/.build/sys/libn/fs.o"
},
{
"arguments": [
@@ -154,13 +161,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/io.o",
- "-c",
"sys/libn/io.c"
],
"directory": "/home/nolln/root",
@@ -175,13 +183,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/os.o",
- "-c",
"sys/libn/os.c"
],
"directory": "/home/nolln/root",
@@ -196,13 +205,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/memory.o",
- "-c",
"sys/libn/memory.c"
],
"directory": "/home/nolln/root",
@@ -217,13 +227,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/mmap.o",
- "-c",
"sys/libn/mmap.c"
],
"directory": "/home/nolln/root",
@@ -238,13 +249,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libn/random.o",
- "-c",
"sys/libn/random.c"
],
"directory": "/home/nolln/root",
@@ -259,18 +271,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/sort.o",
"-c",
- "sys/libn/sort.c"
+ "-o",
+ ".build/sys/libn/string.o",
+ "sys/libn/string.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/sort.c",
- "output": "/home/nolln/root/.build/sys/libn/sort.o"
+ "file": "/home/nolln/root/sys/libn/string.c",
+ "output": "/home/nolln/root/.build/sys/libn/string.o"
},
{
"arguments": [
@@ -280,18 +293,19 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
- "-o",
- ".build/sys/libn/string.o",
"-c",
- "sys/libn/string.c"
+ "-o",
+ ".build/sys/libn/sort.o",
+ "sys/libn/sort.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/libn/string.c",
- "output": "/home/nolln/root/.build/sys/libn/string.o"
+ "file": "/home/nolln/root/sys/libn/sort.c",
+ "output": "/home/nolln/root/.build/sys/libn/sort.o"
},
{
"arguments": [
@@ -301,13 +315,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libmath/basic.o",
- "-c",
"sys/libmath/basic.c"
],
"directory": "/home/nolln/root",
@@ -322,13 +337,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libmath/blas1.o",
- "-c",
"sys/libmath/blas1.c"
],
"directory": "/home/nolln/root",
@@ -343,13 +359,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libmath/blas2.o",
- "-c",
"sys/libmath/blas2.c"
],
"directory": "/home/nolln/root",
@@ -364,13 +381,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libmath/blas3.o",
- "-c",
"sys/libmath/blas3.c"
],
"directory": "/home/nolln/root",
@@ -385,13 +403,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libbio/fasta.o",
- "-c",
"sys/libbio/fasta.c"
],
"directory": "/home/nolln/root",
@@ -406,13 +425,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libbio/newick.o",
- "-c",
"sys/libbio/newick.c"
],
"directory": "/home/nolln/root",
@@ -427,13 +447,14 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
".build/sys/libbio/phylo.o",
- "-c",
"sys/libbio/phylo.c"
],
"directory": "/home/nolln/root",
@@ -448,6 +469,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -460,9 +482,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/dwm/drw.o",
- "-c",
"sys/cmd/dwm/drw.c"
],
"directory": "/home/nolln/root",
@@ -477,6 +499,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -489,9 +512,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/dwm/hook.o",
- "-c",
"sys/cmd/dwm/hook.c"
],
"directory": "/home/nolln/root",
@@ -506,6 +529,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -518,9 +542,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/dwm/client.o",
- "-c",
"sys/cmd/dwm/client.c"
],
"directory": "/home/nolln/root",
@@ -535,6 +559,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -547,9 +572,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/dwm/util.o",
- "-c",
"sys/cmd/dwm/util.c"
],
"directory": "/home/nolln/root",
@@ -564,27 +589,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
- "-I",
- "include",
- "-isystem",
- "include/vendor/libc",
- "-o",
- ".build/sys/cmd/filter/filter.o",
- "-c",
- "sys/cmd/filter/filter.c"
- ],
- "directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/cmd/filter/filter.c",
- "output": "/home/nolln/root/.build/sys/cmd/filter/filter.o"
- },
- {
- "arguments": [
- "/usr/bin/gcc",
- "-g",
- "-march=native",
- "-fno-strict-aliasing",
- "-fwrapv",
- "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -597,9 +602,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/dwm/dwm.o",
- "-c",
"sys/cmd/dwm/dwm.c"
],
"directory": "/home/nolln/root",
@@ -614,6 +619,29 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/sys/cmd/filter/filter.o",
+ "sys/cmd/filter/filter.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/sys/cmd/filter/filter.c",
+ "output": "/home/nolln/root/.build/sys/cmd/filter/filter.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-I/usr/include/freetype2",
@@ -626,9 +654,9 @@
"-I/usr/include/harfbuzz",
"-I/usr/include/glib-2.0",
"-I/usr/lib/glib-2.0/include",
+ "-c",
"-o",
".build/sys/cmd/menu/menu.o",
- "-c",
"sys/cmd/menu/menu.c"
],
"directory": "/home/nolln/root",
@@ -643,6 +671,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-I/usr/include/freetype2",
@@ -655,9 +684,9 @@
"-I/usr/include/harfbuzz",
"-I/usr/include/glib-2.0",
"-I/usr/lib/glib-2.0/include",
+ "-c",
"-o",
".build/sys/cmd/menu/drw.o",
- "-c",
"sys/cmd/menu/drw.c"
],
"directory": "/home/nolln/root",
@@ -672,6 +701,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-I/usr/include/freetype2",
@@ -684,9 +714,9 @@
"-I/usr/include/harfbuzz",
"-I/usr/include/glib-2.0",
"-I/usr/lib/glib-2.0/include",
+ "-c",
"-o",
".build/sys/cmd/menu/util.o",
- "-c",
"sys/cmd/menu/util.c"
],
"directory": "/home/nolln/root",
@@ -701,6 +731,7 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -713,9 +744,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/term/term.o",
- "-c",
"sys/cmd/term/term.c"
],
"directory": "/home/nolln/root",
@@ -730,6 +761,29 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/sys/cmd/walk/walk.o",
+ "sys/cmd/walk/walk.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/sys/cmd/walk/walk.c",
+ "output": "/home/nolln/root/.build/sys/cmd/walk/walk.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/harfbuzz",
@@ -742,9 +796,9 @@
"-I/usr/lib/glib-2.0/include",
"-I",
"include",
+ "-c",
"-o",
".build/sys/cmd/term/x.o",
- "-c",
"sys/cmd/term/x.c"
],
"directory": "/home/nolln/root",
@@ -759,18 +813,41 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
- ".build/sys/cmd/walk/walk.o",
+ ".build/src/pangraph/util.o",
+ "src/pangraph/util.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/util.c",
+ "output": "/home/nolln/root/.build/src/pangraph/util.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
"-c",
- "sys/cmd/walk/walk.c"
+ "-o",
+ ".build/src/pangraph/interval.o",
+ "src/pangraph/interval.c"
],
"directory": "/home/nolln/root",
- "file": "/home/nolln/root/sys/cmd/walk/walk.c",
- "output": "/home/nolln/root/.build/sys/cmd/walk/walk.o"
+ "file": "/home/nolln/root/src/pangraph/interval.c",
+ "output": "/home/nolln/root/.build/src/pangraph/interval.o"
},
{
"arguments": [
@@ -780,17 +857,194 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-Wno-microsoft-anon-tag",
"-I",
"include",
"-isystem",
"include/vendor/libc",
+ "-c",
"-o",
- ".build/src/pangraph/main.o",
+ ".build/src/pangraph/sim.o",
+ "src/pangraph/sim.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/sim.c",
+ "output": "/home/nolln/root/.build/src/pangraph/sim.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/sketch.o",
+ "src/pangraph/sketch.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/sketch.c",
+ "output": "/home/nolln/root/.build/src/pangraph/sketch.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/builder.o",
+ "src/pangraph/builder.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/builder.c",
+ "output": "/home/nolln/root/.build/src/pangraph/builder.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/graph.o",
+ "src/pangraph/graph.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/graph.c",
+ "output": "/home/nolln/root/.build/src/pangraph/graph.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
"-c",
+ "-o",
+ ".build/src/pangraph/io.o",
+ "src/pangraph/io.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/io.c",
+ "output": "/home/nolln/root/.build/src/pangraph/io.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/build.o",
+ "src/pangraph/build.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/build.c",
+ "output": "/home/nolln/root/.build/src/pangraph/build.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/generate.o",
+ "src/pangraph/generate.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/pangraph/generate.c",
+ "output": "/home/nolln/root/.build/src/pangraph/generate.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/pangraph/main.o",
"src/pangraph/main.c"
],
"directory": "/home/nolln/root",
"file": "/home/nolln/root/src/pangraph/main.c",
"output": "/home/nolln/root/.build/src/pangraph/main.o"
+ },
+ {
+ "arguments": [
+ "/usr/bin/gcc",
+ "-g",
+ "-march=native",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-Wno-microsoft-anon-tag",
+ "-I",
+ "include",
+ "-isystem",
+ "include/vendor/libc",
+ "-c",
+ "-o",
+ ".build/src/timetree/main.o",
+ "src/timetree/main.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "/home/nolln/root/src/timetree/main.c",
+ "output": "/home/nolln/root/.build/src/timetree/main.o"
}
]
diff --git a/include/libbio.h b/include/libbio.h
index b3d0426..f84b081 100644
--- a/include/libbio.h
+++ b/include/libbio.h
@@ -53,7 +53,7 @@ typedef struct bio·SeqReader bio·SeqReader;
typedef struct bio·Seq
{
- int len;
+ vlong len;
char *name;
char *s;
char *q;
diff --git a/include/libn.h b/include/libn.h
index 5d557ce..2cf29c7 100644
--- a/include/libn.h
+++ b/include/libn.h
@@ -57,7 +57,7 @@ typedef struct mem·Allocator {
void *(*alloc)(void *heap, uint n, ulong size);
void (*free)(void *heap, void *ptr);
} mem·Allocator;
-extern mem·Allocator sys·Memory;
+extern mem·Allocator sys·Memory;
typedef struct mem·Reallocator {
void *(*alloc)(void *iface, uint n, ulong size);
@@ -159,6 +159,7 @@ enum SeekPos
seek·end = SEEK_END
};
+/* XXX: change casing */
enum
{
ReadOK = R_OK,
@@ -180,6 +181,7 @@ int io·putstring(io·Stream *s, string str);
int io·write(io·Stream *s, int sz, int n, void *buf);
int io·flush(io·Stream *s);
int io·seek(io·Stream *s, long off, enum SeekPos whence);
+long io·tell(io·Stream *s);
/* basic os helpers */
int os·exists(byte *path, int flag);
@@ -193,13 +195,6 @@ typedef struct io·Reader
} io·Reader;
extern io·Reader sys·Reader;
-/*
-typedef struct io·LineReader
-{
- int (*readln)(void*, int n, void *buf);
-} io·LineReader;
-*/
-
typedef struct io·Peeker
{
byte (*get)(void*);
@@ -207,12 +202,26 @@ typedef struct io·Peeker
} io·Peeker;
extern io·Peeker sys·Peeker;
-typedef struct io·FullReader
+typedef struct io·Seeker
+{
+ int (*seek)(void *skr, long off, enum SeekPos whence);
+ long (*tell)(void *skr);
+} io·Seeker;
+extern io·Seeker sys·Seeker;
+
+typedef struct io·SeekReader
+{
+ io·Seeker;
+ io·Reader;
+} io·SeekReader;
+extern io·SeekReader sys·SeekReader;
+
+typedef struct io·PeekReader
{
io·Reader;
io·Peeker;
-} io·FullReader;
-extern io·FullReader sys·FullReader;
+} io·PeekReader;
+extern io·PeekReader sys·PeekReader;
typedef struct io·Writer
{
@@ -227,12 +236,12 @@ typedef struct io·Putter
} io·Putter;
extern io·Putter sys·Putter;
-typedef struct io·FullWriter
+typedef struct io·PutWriter
{
io·Writer;
io·Putter;
-} io·FullWriter;
-extern io·FullWriter sys·FullWriter;
+} io·PutWriter;
+extern io·PutWriter sys·PutWriter;
typedef struct io·ReadWriter
{
@@ -348,13 +357,15 @@ typedef void gz·Stream;
/* interfaces */
extern io·Reader gz·Reader;
extern io·Peeker gz·Peeker;
-extern io·FullReader gz·FullReader;
+extern io·Seeker gz·Seeker;
+extern io·SeekReader gz·SeekReader;
+extern io·PeekReader gz·PeekReader;
extern io·Writer gz·Writer;
extern io·Putter gz·Putter;
-extern io·FullWriter gz·FullWriter;
+extern io·PutWriter gz·PutWriter;
extern io·ReadWriter gz·ReadWriter;
-
+
gz·Stream *gz·open(byte *path, byte *mode);
error gz·close(gz·Stream* s);
int gz·read(gz·Stream *s, int sz, int n, void* buf);
@@ -366,7 +377,8 @@ error gz·putbyte(gz·Stream *s, byte str);
error gz·putstring(gz·Stream *s, byte *str);
int gz·printf(gz·Stream *s, byte *fmt, ...);
error gz·flush(gz·Stream *s);
-vlong gz·seek(gz·Stream *s, long off, enum SeekPos whence);
+int gz·seek(gz·Stream *s, long off, enum SeekPos whence);
+long gz·tell(gz·Stream *s);
// -----------------------------------------------------------------------------
// libjson
diff --git a/include/libn/macro/map.h b/include/libn/macro/map.h
index 0743c1b..7c2f7ae 100644
--- a/include/libn/macro/map.h
+++ b/include/libn/macro/map.h
@@ -35,11 +35,11 @@ static const double __ac_HASH_UPPER = 0.77;
map = alloc((h), 1, sizeof(*map)); \
return map
-#define MAP_FREE(map, free, h) \
- free(h, map->keys); \
- free(h, map->flags); \
- free(h, map->vals); \
- free(h, map);
+#define MAP_FREE(map, mem, heap) \
+ mem.free(heap, map->keys); \
+ mem.free(heap, map->flags); \
+ mem.free(heap, map->vals); \
+ mem.free(heap, map);
#define MAP_RESET(map) \
if (map && map->flags) { \
@@ -72,7 +72,7 @@ static const double __ac_HASH_UPPER = 0.77;
} else \
i = 0;
-#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc, alloc, free, h) \
+#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc, mem, heap) \
int32 *new_flags = nil; \
int32 j = 1; \
{ \
@@ -82,25 +82,25 @@ static const double __ac_HASH_UPPER = 0.77;
if (map->size >= (int32)(new_n_buckets * __ac_HASH_UPPER + 0.5)) \
j = 0; \
else { \
- new_flags = alloc(h, __ac_fsize(new_n_buckets), sizeof(int32)); \
+ new_flags = mem.alloc(heap, __ac_fsize(new_n_buckets), sizeof(int32)); \
if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(int32)); \
if (map->n_buckets < new_n_buckets) { /* expand */ \
- key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \
+ key_t *new_keys = mem.alloc(heap, new_n_buckets, sizeof(key_t)); \
if (!new_keys) { \
- free(h, new_flags); \
+ mem.free(heap, new_flags); \
return -1; \
} \
memcpy(new_keys, map->keys, sizeof(key_t) * map->n_buckets); \
- free(h, map->keys); \
+ mem.free(heap, map->keys); \
map->keys = new_keys; \
- val_t *new_vals = alloc(h, new_n_buckets, sizeof(val_t)); \
+ val_t *new_vals = mem.alloc(heap, new_n_buckets, sizeof(val_t)); \
if (!new_vals) { \
- free(h, new_flags); \
+ mem.free(heap, new_flags); \
return -1; \
} \
memcpy(new_vals, map->vals, sizeof(val_t) * map->n_buckets); \
- free(h, map->vals); \
+ mem.free(heap, map->vals); \
map->vals = new_vals; \
} \
} \
@@ -142,17 +142,17 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (map->n_buckets > new_n_buckets) { /* shrink the hash table */ \
- key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \
+ key_t *new_keys = mem.alloc(heap, new_n_buckets, sizeof(key_t)); \
memcpy(new_keys, map->keys, sizeof(key_t) * map->n_buckets); \
- free(h, map->keys); \
+ mem.free(heap, map->keys); \
map->keys = new_keys; \
\
- val_t *new_vals = alloc(h, new_n_buckets, sizeof(val_t)); \
+ val_t *new_vals = mem.alloc(heap, new_n_buckets, sizeof(val_t)); \
memcpy(new_vals, map->vals, sizeof(val_t) * map->n_buckets); \
- free(h, map->vals); \
+ mem.free(heap, map->vals); \
map->vals = new_vals; \
} \
- free(h, map->flags); /* free the working space */ \
+ mem.free(heap, map->flags); /* free the working space */ \
map->flags = new_flags; \
map->n_buckets = new_n_buckets; \
map->n_occupied = map->size; \
@@ -235,10 +235,10 @@ static const double __ac_HASH_UPPER = 0.77;
set = alloc((h), 1, sizeof(*set)); \
return set
-#define SET_FREE(set, free, h) \
- free(h, set->keys); \
- free(h, set->flags); \
- free(h, set)
+#define SET_FREE(set, mem, heap) \
+ mem.free(heap, set->keys); \
+ mem.free(heap, set->flags); \
+ mem.free(heap, set)
#define SET_RESET(set) \
if (set && set->flags) { \
@@ -271,7 +271,7 @@ static const double __ac_HASH_UPPER = 0.77;
} else \
i = 0;
-#define SET_GROW(set, key_t, new_n_buckets, hashfunc, alloc, free, h) \
+#define SET_GROW(set, key_t, new_n_buckets, hashfunc, mem, heap) \
int32 *new_flags = nil; \
int32 j = 1; \
{ \
@@ -281,17 +281,17 @@ static const double __ac_HASH_UPPER = 0.77;
if (set->size >= (int32)(new_n_buckets * __ac_HASH_UPPER + 0.5)) \
j = 0; \
else { \
- new_flags = alloc(h, __ac_fsize(new_n_buckets), sizeof(int32)); \
+ new_flags = mem.alloc(heap, __ac_fsize(new_n_buckets), sizeof(int32)); \
if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(int32)); \
if (set->n_buckets < new_n_buckets) { /* expand */ \
- key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \
+ key_t *new_keys = mem.alloc(heap, new_n_buckets, sizeof(key_t)); \
if (!new_keys) { \
- free(h, new_flags); \
+ mem.free(heap, new_flags); \
return -1; \
} \
memcpy(new_keys, set->keys, sizeof(key_t) * set->n_buckets); \
- free(h, set->keys); \
+ mem.free(heap, set->keys); \
set->keys = new_keys; \
} \
} \
@@ -325,12 +325,12 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (set->n_buckets > new_n_buckets) { /* shrink the hash table */ \
- key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \
+ key_t *new_keys = mem.alloc(heap, new_n_buckets, sizeof(key_t)); \
memcpy(new_keys, set->keys, sizeof(key_t) * set->n_buckets); \
- free(h, set->keys); \
+ mem.free(heap, set->keys); \
set->keys = new_keys; \
} \
- free(h, set->flags); /* free the working space */ \
+ mem.free(heap, set->flags); /* free the working space */ \
set->flags = new_flags; \
set->n_buckets = new_n_buckets; \
set->n_occupied = set->size; \
@@ -391,10 +391,10 @@ static const double __ac_HASH_UPPER = 0.77;
++set->size; \
} else \
*err = 0; \
- return x
+ return x
#define SET_DEL(set, x) \
if (x != set->n_buckets && !__ac_iseither(set->flags, x)) { \
__ac_set_isdel_true(set->flags, x); \
--set->size; \
- }
+ }
diff --git a/rules.mk b/rules.mk
index 7e5afa1..2532936 100644
--- a/rules.mk
+++ b/rules.mk
@@ -7,7 +7,7 @@ all: targets
debug: CFLAGS += -DDEBUG -g -fsanitize=address
debug: targets
-release: CFLAGS += -O3 -mtune=native -flto -ffast-math #-DNDEBUG
+release: CFLAGS += -O3 -mtune=native -flto -ffast-math #-DNDEBUG
release: targets
# Targets & array of sources & intermediates
@@ -48,9 +48,9 @@ clean:
@echo removing object files
@rm -f $(OBJS)
@echo removing dependency files
- @rm -f $(DEPS)
+ @rm -f $(DEPS)
@echo removing libraries
- @rm -f $(LIBS)
+ @rm -f $(LIBS)
@echo removing binaries
@rm -f $(BINS)
@echo removing unit tests
diff --git a/sys/cmd/cc/cc.c b/sys/cmd/cc/cc.c
index 3602643..8ad0022 100644
--- a/sys/cmd/cc/cc.c
+++ b/sys/cmd/cc/cc.c
@@ -397,7 +397,7 @@ main(int argc, byte *argv[])
// NOTE: This is just for my comfort during debugging.
pushinclude("/home/nolln/root/include");
pushinclude("/home/nolln/root/include/vendor/libc");
-
+
src = (argc == 0) ? "<stdin>" : argv[0];
intern(&src);
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c
index 0963fb9..33fc5d0 100644
--- a/sys/cmd/cc/lex.c
+++ b/sys/cmd/cc/lex.c
@@ -813,7 +813,7 @@ static
int
moresymtab(SymTab *tab, int n)
{
- MAP_GROW(tab, string, Sym*, n, PTR_HASH, ·calloc, ·free, nil);
+ MAP_GROW(tab, string, Sym*, n, PTR_HASH, sys·Memory, nil);
}
static
diff --git a/sys/libbio/fasta.c b/sys/libbio/fasta.c
index 078325a..0c47199 100644
--- a/sys/libbio/fasta.c
+++ b/sys/libbio/fasta.c
@@ -190,7 +190,7 @@ readfasta(bio·SeqReader *rdr, bio·Seq *seq, byte hdr, byte stop)
{
error err;
byte *beg;
-
+
if (rdr->eof && rdr->b == rdr->bend-1)
return EOF;
@@ -236,13 +236,6 @@ SEQLOOP:
rdr->b++;
}
-#if 0
- for(byte *cb = rdr->seq->b+rdr->seq->off; cb != rdr->seq->it; ++cb) {
- if(*cb == 0) {
- printf("ERROR @ pos=%ld: Found zero byte\n", cb - rdr->seq->b+rdr->seq->off);
- }
- }
-#endif
push(&rdr->seq, rdr->b - beg, beg);
diff --git a/sys/libn/fs.c b/sys/libn/fs.c
index 10cd93e..e89ef07 100644
--- a/sys/libn/fs.c
+++ b/sys/libn/fs.c
@@ -12,20 +12,6 @@ struct Key
dev_t dev;
};
-static
-void*
-xalloc(void *_, int n, uintptr size)
-{
- return malloc(n*size);
-}
-
-static
-void
-xfree(void *_, void *ptr)
-{
- return free(ptr);
-}
-
#define hash(k) ((int32)k.ino ^ (int32)k.dev)
#define equal(k1, k2) (k1.ino == k2.ino && k1.dev == k2.dev)
@@ -38,7 +24,7 @@ static
int
morehistory(fs·History *h, int n)
{
- SET_GROW(h, struct Key, n, hash, xalloc, xfree, nil);
+ SET_GROW(h, struct Key, n, hash, sys·Memory, nil);
}
static
@@ -62,7 +48,7 @@ static
void
delete(fs·History *h)
{
- SET_FREE(h, xfree, nil);
+ SET_FREE(h, sys·Memory, nil);
}
#undef hash
diff --git a/sys/libn/gz.c b/sys/libn/gz.c
index 79bc13f..040d25a 100644
--- a/sys/libn/gz.c
+++ b/sys/libn/gz.c
@@ -7,15 +7,16 @@
// interface implementations
/* actual interfaces */
-io·Reader gz·FileReader = (io·Reader){ gz·read };
-io·Peeker gz·FilePeeker = (io·Peeker){ gz·getbyte, gz·ungetbyte };
-io·FullReader gz·FullFileReader = (io·FullReader){ gz·read, gz·getbyte, gz·ungetbyte };
+io·Reader gz·Reader = (io·Reader){ gz·read };
+io·Peeker gz·Peeker = (io·Peeker){ gz·getbyte, gz·ungetbyte };
+io·Seeker gz·Seeker = (io·Seeker){ gz·seek, gz·tell };
+io·PeekReader gz·Peekreader = (io·PeekReader){ gz·read, gz·getbyte, gz·ungetbyte };
-io·Writer gz·FileWriter = (io·Writer){ gz·write };
-io·Putter gz·FilePutter = (io·Putter){ gz·putbyte, gz·putstring };
-io·FullWriter gz·FullFileWriter = (io·FullWriter){ gz·write, gz·putbyte, gz·putstring };
+io·Writer gz·Writer = (io·Writer){ gz·write };
+io·Putter gz·Putter = (io·Putter){ gz·putbyte, gz·putstring };
+io·PutWriter gz·PutWriter = (io·PutWriter){ gz·write, gz·putbyte, gz·putstring };
-io·ReadWriter gz·FileReadWriter = (io·ReadWriter){ gz·read, gz·write };
+io·ReadWriter gz·ReadWriter = (io·ReadWriter){ gz·read, gz·write };
// -----------------------------------------------------------------------
// functions implementations
@@ -69,13 +70,13 @@ gz·write(gz·Stream *s, int sz, int n, void* buf)
return gzwrite(s, buf, n*sz);
}
-error
+error
gz·putbyte(gz·Stream *s, byte c)
{
return gzputc(s, c);
}
-error
+error
gz·putstring(gz·Stream *s, byte *str)
{
return gzputs(s, str);
@@ -100,7 +101,7 @@ gz·flush(gz·Stream *s)
return gzflush(s, Z_FINISH);
}
-vlong
+int
gz·seek(gz·Stream *s, long off, enum SeekPos whence)
{
return gzseek(s, off, whence);
diff --git a/sys/libn/io.c b/sys/libn/io.c
index f0d270e..ff4fe67 100644
--- a/sys/libn/io.c
+++ b/sys/libn/io.c
@@ -40,21 +40,37 @@ error
return io·putbyte((io·Stream *)wtr, c);
}
-static
+static
int
·puts(void *wtr, string s)
{
return io·putstring((io·Stream *)wtr, s);
}
+static
+int
+·seek(void *skr, long off, enum SeekPos whence)
+{
+ return io·seek((io·Stream *)skr, off, whence);
+}
+
+static
+long
+·tell(void *skr)
+{
+ return io·tell((io·Stream *)skr);
+}
+
/* actual interfaces */
io·Reader sys·Reader = (io·Reader){ ·read };
+io·Seeker sys·Seeker = (io·Seeker){ ·seek, ·tell };
io·Peeker sys·Peeker = (io·Peeker){ ·get, ·unget };
-io·FullReader sys·FullReader = (io·FullReader){ ·read, ·get, ·unget };
+io·SeekReader sys·SeekReader = (io·SeekReader){ ·seek, ·tell, ·read };
+io·PeekReader sys·PeekReader = (io·PeekReader){ ·read, ·get, ·unget };
io·Writer sys·Writer = (io·Writer){ ·write };
io·Putter sys·Putter = (io·Putter){ ·put, ·puts };
-io·FullWriter sys·FullWriter = (io·FullWriter){ ·write, ·put, ·puts };
+io·PutWriter sys·PutWriter = (io·PutWriter){ ·write, ·put, ·puts };
io·ReadWriter sys·ReadWriter = (io·ReadWriter){ ·read, ·write };
@@ -152,3 +168,9 @@ io·seek(io·Stream *s, long off, enum SeekPos origin)
{
return fseek(s, off, origin);
}
+
+long
+io·tell(io·Stream *s)
+{
+ return ftell(s);
+}
diff --git a/sys/libn/memory.c b/sys/libn/memory.c
index 1c7ab07..795fe1f 100644
--- a/sys/libn/memory.c
+++ b/sys/libn/memory.c
@@ -1,19 +1,19 @@
#include <u.h>
#include <libn.h>
-static
-void
+static
+void
·free(void* _, void* ptr) {
return free(ptr);
}
-static
+static
void *
·alloc(void* _, uint n, ulong size) {
return malloc(n*size);
}
-static
+static
void *
·calloc(void* _, uint n, ulong size) {
return calloc(n, size);
@@ -26,7 +26,7 @@ void *
}
mem·Allocator sys·Memory = {
- .alloc = ·alloc,
+ .alloc = ·calloc,
.free = ·free
};
diff --git a/sys/libn/random.c b/sys/libn/random.c
index 551d1e9..237127e 100644
--- a/sys/libn/random.c
+++ b/sys/libn/random.c
@@ -107,17 +107,127 @@ rng·randi(int max)
return r % max;
}
+/*
+ * Ahrens, J. H., & Dieter, U. (1982).
+ * Computer Generation of Poisson Deviates from Modified Normal Distributions.
+ */
+static double factorial[10] = {1., 1., 2., 6., 24., 120., 720., 5040., 40320., 362880.};
+static double coeffs[9] = {
+ -.500000000, +.333333333, -.249999856,
+ +.200011780, -.166684875, +.142187833,
+ -.124196313, +.125005956, -.114265030,
+};
+
+static inline
+double
+log1pmx(double x, double off)
+{
+ int i;
+ double r, t;
+
+ if(-0.25 < x && x < 0.25) {
+ r = 0;
+ t = 1;
+ for(i=0;i<arrlen(coeffs);i++) {
+ r += coeffs[i]*t;
+ t *= x;
+ }
+
+ return x*x*r;
+ }
+ return log(1+x) - off;
+}
+
+static inline
+double
+procf(double mu, double s, int64 K, double *px, double *py, double *fx, double *fy)
+{
+ double d, V, X;
+ double w, b1, b2, c1, c2, c3, c0, c;
+
+ w = 0.3989422804014327/s;
+ b1 = 0.041666666666666664/mu;
+ b2 = 0.3*b1*b1;
+ c3 = 0.14285714285714285*b1*b2;
+ c2 = b2 - 15.*c3;
+ c1 = b1 - 6.*b2 + 45.*c3;
+ c0 = 1 - b1 + 3.*b2 - 15.*c3;
+ c = .1069/mu;
+
+ if(K < 10) {
+ *px = -mu;
+ *py = pow(mu,K) / factorial[K];
+ }else{
+ d = 0.08333333333333333/K;
+ d = d - 4.8*d*d*d;
+ V = (mu - K) / K;
+
+ *px = K*log1pmx(V,mu-K) - d;
+ *py = 0.3989422804014327/sqrt(K);
+ }
+
+ X = (K - mu + 0.5)/s;
+ *fx = -0.5*X*X;
+ *fy = w*(((c3*X*X + c2)*X*X + c1)*X*X + c0);
+
+ return c;
+}
+
+static inline
+uint64
+bigpoisson(double mu)
+{
+ int64 L,K;
+ double G,s,d,U,E,T;
+ double px,py,fx,fy,c;
+
+ s = sqrt(mu);
+ d = 6*mu*mu;
+ L = floor(mu - 1.1484);
+
+stepN:
+ G = mu + s*rng·normal();
+ K = floor(G);
+ if(K<0)
+ goto stepP;
+stepI:
+ if(K>=L)
+ return K;
+stepS:
+ U = rng·random();
+ if(d*U >= (mu-K)*(mu-K)*(mu-K))
+ return K;
+stepP:
+ if(G < 0)
+ goto stepE;
+stepQ:
+ c = procf(mu, s, K, &px, &py, &fx, &fy);
+stepE:
+ E = rng·exponential(1.0);
+ U = rng·random();
+ U = U + U - 1;
+ T = 1.8 + copysign(E,U);
+ if(T < 0.6744)
+ goto stepE;
+ K = floor(mu + s*T);
+ c = procf(mu, s, K, &px, &py, &fx, &fy);
+stepH:
+ if(c*fabs(U) > (py*exp(px + E) - fy*exp(fx + E)))
+ goto stepE;
+ return K;
+}
+
uint64
rng·poisson(double mean)
{
- uint64 n;
- double c;
+ int64 n;
+ double z;
if(mean<10.0) {
- for(n=0, c=rng·exponential(1.0); c<mean; ++n, c+=rng·exponential(1.0))
+ for(n=0, z=rng·exponential(1.0); z<mean; ++n, z+=rng·exponential(1.0))
;
return n;
}
- return 0;
+ return bigpoisson(mean);
}