Showing preview only (629K chars total). Download the full file or copy to clipboard to get everything.
Repository: orangeduck/Cello
Branch: master
Commit: 61ee5c3d9bca
Files: 135
Total size: 593.7 KB
Directory structure:
gitextract_qcet_0lf/
├── .gitattributes
├── .gitignore
├── LICENSE.md
├── Makefile
├── README.md
├── TODO.md
├── benchmarks/
│ ├── Dict/
│ │ ├── dict_c.c
│ │ ├── dict_cello.c
│ │ ├── dict_cpp.cpp
│ │ ├── dict_cs.cs
│ │ ├── dict_d.d
│ │ ├── dict_go.go
│ │ ├── dict_java.java
│ │ ├── dict_javascript.js
│ │ ├── dict_lua.lua
│ │ ├── dict_perl.pl
│ │ ├── dict_python.py
│ │ └── dict_ruby.rb
│ ├── GC/
│ │ ├── gc_c.c
│ │ ├── gc_cello.c
│ │ ├── gc_cpp.cpp
│ │ ├── gc_java.java
│ │ ├── gc_javascript.js
│ │ ├── gc_lua.lua
│ │ ├── gc_python.py
│ │ └── gc_ruby.rb
│ ├── List/
│ │ ├── list_c.c
│ │ ├── list_cello.c
│ │ ├── list_cpp.cpp
│ │ ├── list_java.java
│ │ ├── list_javascript.js
│ │ ├── list_lua.lua
│ │ ├── list_python.py
│ │ └── list_ruby.rb
│ ├── Map/
│ │ ├── dict.lua
│ │ ├── map_c.c
│ │ ├── map_cello.c
│ │ ├── map_cpp.cpp
│ │ ├── map_cs.cs
│ │ ├── map_d.d
│ │ ├── map_go.go
│ │ ├── map_java.java
│ │ ├── map_javascript.js
│ │ ├── map_lua.lua
│ │ ├── map_perl.pl
│ │ ├── map_python.py
│ │ ├── map_ruby.rb
│ │ ├── rb.lua
│ │ └── redblack.lua
│ ├── Matmul/
│ │ ├── matmul_c.c
│ │ ├── matmul_cello.c
│ │ ├── matmul_cpp.cpp
│ │ ├── matmul_cs.cs
│ │ ├── matmul_d.d
│ │ ├── matmul_dart.dart
│ │ ├── matmul_go.go
│ │ ├── matmul_java.java
│ │ ├── matmul_javascript.js
│ │ ├── matmul_lua.lua
│ │ ├── matmul_perl.pl
│ │ ├── matmul_python.py
│ │ ├── matmul_r.R
│ │ └── matmul_ruby.rb
│ ├── Nbodies/
│ │ ├── nbodies_c.c
│ │ ├── nbodies_cello.c
│ │ ├── nbodies_cpp.cpp
│ │ ├── nbodies_java.java
│ │ ├── nbodies_javascript.js
│ │ ├── nbodies_lua.lua
│ │ ├── nbodies_python.py
│ │ └── nbodies_ruby.rb
│ ├── Sudoku/
│ │ ├── sudoku_c.c
│ │ ├── sudoku_cello.c
│ │ ├── sudoku_cpp.cpp
│ │ ├── sudoku_cs.cs
│ │ ├── sudoku_d.d
│ │ ├── sudoku_dart.dart
│ │ ├── sudoku_go.go
│ │ ├── sudoku_java.java
│ │ ├── sudoku_javascript.js
│ │ ├── sudoku_lua.lua
│ │ ├── sudoku_perl.pl
│ │ ├── sudoku_python.py
│ │ └── sudoku_ruby.rb
│ ├── benchmark
│ ├── benchmark.sh
│ ├── ext/
│ │ ├── cleantxt.c
│ │ ├── genint.c
│ │ ├── kbtree.h
│ │ ├── khash.h
│ │ ├── kvec.h
│ │ ├── regexp9.c
│ │ ├── regexp9.h
│ │ ├── sudoku
│ │ └── sudoku.txt
│ └── graphs.py
├── examples/
│ ├── cello_world.c
│ ├── help.c
│ ├── iteration.c
│ ├── newtype.c
│ ├── object.c
│ ├── ranges.c
│ ├── table.c
│ └── threads.c
├── include/
│ └── Cello.h
├── src/
│ ├── Alloc.c
│ ├── Array.c
│ ├── Assign.c
│ ├── Cmp.c
│ ├── Concat.c
│ ├── Doc.c
│ ├── Exception.c
│ ├── File.c
│ ├── Function.c
│ ├── GC.c
│ ├── Get.c
│ ├── Hash.c
│ ├── Iter.c
│ ├── Len.c
│ ├── List.c
│ ├── Num.c
│ ├── Pointer.c
│ ├── Push.c
│ ├── Resize.c
│ ├── Show.c
│ ├── Start.c
│ ├── String.c
│ ├── Table.c
│ ├── Thread.c
│ ├── Tree.c
│ ├── Tuple.c
│ └── Type.c
└── tests/
├── ptest.c
├── ptest.h
└── test.c
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
text=auto
================================================
FILE: .gitignore
================================================
# Main
*.log
*~
*.libs
*.o
*.la
*.so*
*.a
*.lo
*.dll
*.exe
*.gz
*.class
# Tests
test.bin
test.txt
test.exe
test
# Benchmarking
profile.txt
# Dist
libCello*
# VIM related
.clang_complete
# benchmark programs
benchmarks/Dict/dict_c
benchmarks/Dict/dict_cello
benchmarks/Dict/dict_cpp
benchmarks/ext/genint
benchmarks/GC/gc_c
benchmarks/GC/gc_cello
benchmarks/GC/gc_cpp
benchmarks/List/list_c
benchmarks/List/list_cello
benchmarks/List/list_cpp
benchmarks/Map/map_c
benchmarks/Map/map_cello
benchmarks/Map/map_cpp
benchmarks/Matmul/matmul_c
benchmarks/Matmul/matmul_cello
benchmarks/Matmul/matmul_cpp
benchmarks/Nbodies/nbodies_c
benchmarks/Nbodies/nbodies_cello
benchmarks/Nbodies/nbodies_cpp
benchmarks/Sudoku/sudoku_c
benchmarks/Sudoku/sudoku_cello
benchmarks/Sudoku/sudoku_cpp
================================================
FILE: LICENSE.md
================================================
Licensed Under BSD
Copyright (c) 2012, Daniel Holden
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
================================================
FILE: Makefile
================================================
CC ?= gcc
AR ?= ar
VERSION = 2.1.0
PACKAGE = libCello-$(VERSION)
BINDIR = ${PREFIX}/bin
INCDIR = ${PREFIX}/include
LIBDIR = ${PREFIX}/lib
SRC := $(wildcard src/*.c)
OBJ := $(addprefix obj/,$(notdir $(SRC:.c=.o)))
TESTS := $(wildcard tests/*.c)
TESTS_OBJ := $(addprefix obj/,$(notdir $(TESTS:.c=.o)))
EXAMPLES := $(wildcard examples/*.c)
EXAMPLES_OBJ := $(addprefix obj/,$(notdir $(EXAMPLES:.c=.o)))
EXAMPLES_EXE := $(EXAMPLES:.c=)
CFLAGS = -I ./include -std=gnu99 -Wall -Wno-unused -g -ggdb
PLATFORM := $(shell uname)
COMPILER := $(shell $(CC) -v 2>&1 )
ifeq ($(findstring CYGWIN,$(PLATFORM)),CYGWIN)
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
ifneq (,$(wildcard ${LIBDIR}/libdbghelp.a))
LIBS += -lDbgHelp
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else ifeq ($(findstring MINGW,$(PLATFORM)),MINGW)
# MSYS2
ifeq ($(findstring MINGW32,$(MSYSTEM)),MINGW32)
CC = i686-w64-mingw32-gcc
PREFIX ?= /mingw32
else ifeq ($(findstring MINGW64,$(MSYSTEM)),MINGW64)
CC = x86_64-w64-mingw32-gcc
PREFIX ?= /mingw64
else ifeq ($(findstring MSYS,$(MSYSTEM)),MSYS)
CC = gcc
PREFIX ?= /usr
else
# MinGW64 mingw-builds
prefix ?= c:/mingw64/x86_64-w64-mingw32
endif
DYNAMIC = libCello.dll
STATIC = libCello.a
ifneq (,$(wildcard ${LIBDIR}/libdbghelp.a))
LIBS += -lDbgHelp
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = cp $(STATIC) $(LIBDIR)/$(STATIC); cp $(DYNAMIC) $(BINDIR)/$(DYNAMIC)
INSTALL_INC = cp -r include/Cello.h $(INCDIR)
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC); rm -f ${BINDIR}/$(DYNAMIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else ifeq ($(findstring FreeBSD,$(PLATFORM)),FreeBSD)
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
CFLAGS += -fPIC
ifneq (,$(wildcard ${LIBDIR}/libexecinfo.a))
LIBS += -lexecinfo
LFLAGS += -rdynamic
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
CFLAGS += -fPIC
ifneq (,$(wildcard ${LIBDIR}/libexecinfo.a))
LIBS += -lexecinfo
LFLAGS += -rdynamic
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
endif
# Libraries
all: $(DYNAMIC) $(STATIC)
$(DYNAMIC): $(OBJ)
$(CC) $(OBJ) -shared $(LFLAGS) $(LIBS) -o $@
$(STATIC): $(OBJ)
$(AR) rcs $@ $(OBJ)
obj/%.o: src/%.c include/Cello.h | obj
$(CC) $< -c $(CFLAGS) -o $@
obj:
mkdir -p obj
# Tests
check: CFLAGS += -Werror -g -ggdb
check: $(TESTS_OBJ) $(STATIC)
$(CC) $(TESTS_OBJ) $(STATIC) $(LIBS) $(LFLAGS) -o ./tests/test
./tests/test
rm -f ./tests/test.bin ./tests/test.txt
obj/%.o: tests/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
# Benchmarks
ifeq ($(findstring Darwin,$(PLATFORM)),Darwin)
bench: CFLAGS += -DCELLO_NDEBUG -O3
bench: clean $(STATIC)
cd benchmarks; ./benchmark.sh; cd ../
else
bench: CFLAGS += -DCELLO_NDEBUG -pg -O3
bench: clean $(STATIC)
cd benchmarks; ./benchmark; cd ../
endif
# Examples
examples: $(EXAMPLES_EXE)
examples/%: CFLAGS += -Werror
examples/%: examples/%.c $(STATIC) | obj
$(CC) $< $(STATIC) $(CFLAGS) $(LIBS) $(LFLAGS) -o $@
# Dist
dist: all | $(PACKAGE)
cp -R examples include src tests LICENSE.md Makefile README.md $(PACKAGE)
tar -czf $(PACKAGE).tar.gz $(PACKAGE) --exclude='*.exe' --exclude='*.pdb'
$(PACKAGE):
mkdir -p $(PACKAGE)
# Clean
clean:
rm -f $(OBJ) $(TESTS_OBJ) $(EXAMPLES_OBJ) $(STATIC) $(DYNAMIC) tests/test
# Install
install: all
$(INSTALL_LIB)
$(INSTALL_INC)
# Uninstall
uninstall:
$(UNINSTALL_LIB)
$(UNINSTALL_INC)
================================================
FILE: README.md
================================================
Cello
=====
__Cello__ is a _library_ that brings higher level programming to C.
By acting as a _modern_, _powerful_ runtime system Cello makes many things easy
that were previously impractical or awkward in C such as:
* __Generic Data Structures__
* __Polymorphic Functions__
* __Interfaces / Type Classes__
* __Constructors / Destructors__
* __Optional Garbage Collection__
* __Exceptions__
* __Reflection__
And because Cello works seamlessly alongside standard C you get all the other
benefits such as great performance, powerful tooling, and extensive
libraries.
Examples
--------
```c
#include "Cello.h"
int main(int argc, char** argv) {
/* Stack objects are created using "$" */
var i0 = $(Int, 5);
var i1 = $(Int, 3);
var i2 = $(Int, 4);
/* Heap objects are created using "new" */
var items = new(Array, Int, i0, i1, i2);
/* Collections can be looped over */
foreach (item in items) {
print("Object %$ is of type %$\n",
item, type_of(item));
}
/* Heap objects destructed via Garbage Collection */
return 0;
}
```
```c
#include "Cello.h"
int main(int argc, char** argv) {
/* Shorthand $ can be used for basic types */
var prices = new(Table, String, Int);
set(prices, $S("Apple"), $I(12));
set(prices, $S("Banana"), $I( 6));
set(prices, $S("Pear"), $I(55));
/* Tables also support iteration */
foreach (key in prices) {
var val = get(prices, key);
print("Price of %$ is %$\n", key, val);
}
return 0;
}
```
Articles
--------
Learning Resources:
* [Installation](http://libcello.org/learn/installation)
* [Cello World](http://libcello.org/learn/cello-world)
* [Quickstart](http://libcello.org/learn/quickstart)
* [Common Queries / Pitfalls](http://libcello.org/learn/queries-and-pitfalls)
Articles about its creation and internal workings:
* [Best Improvements of Cello 2.0](http://libcello.org/learn/best-improvements-of-cello-2.0)
* [A Fat Pointer Library](http://libcello.org/learn/a-fat-pointer-library)
* [Cello vs C++ vs ObjC](http://libcello.org/learn/cello-vs-cpp-vs-objc)
* [Benchmarks](http://libcello.org/learn/benchmarks)
* [Garbage Collection](http://libcello.org/learn/garbage-collection)
More Examples
-------------
```c
#include "Cello.h"
int main(int argc, char** argv) {
var items = new(Array, Int,
$I( 8), $I( 5), $I(20),
$I(15), $I(16), $I(98));
/* Iterate over indices using "range" */
foreach (i in range($I(len(items)))) {
print("Item Range %i is %i\n", i, get(items, i));
}
/* Iterate over every other item with "slice" */
foreach (item in slice(items, _, _, $I(2))) {
print("Item Slice %i\n", item);
}
return 0;
}
```
```c
#include "Cello.h"
/* Define a normal C structure */
struct Point {
float x, y;
};
/* Make it compatible with Cello */
var Point = Cello(Point);
int main(int argc, char** argv) {
/* Create on Stack or Heap */
var p0 = $(Point, 0.0, 1.0);
var p1 = new(Point, $(Point, 0.0, 2.0));
/* It can be shown, compared, hashed, etc...
**
** p0: <'Point' At 0x000000000022FC58>
** p1: <'Point' At 0x00000000004C7CC8>
** cmp: 1
** hash: 2849275892l
*/
print("p0: %$\np1: %$\ncmp: %i\nhash: %ul\n",
p0, p1, $I(cmp(p0, p1)), $I(hash(p0)));
/* And collected by the GC when out of scope */
return 0;
}
```
F.A.Q
-----
* __Why does this exist?__
I made Cello as a fun experiment to see what C looks like hacked to its limits.
As well as being a powerful library and toolkit, it should be interesting to
those who want to explore what is possible in C.
* __How does it work?__
I recommend reading
[A Fat Pointer Library](http://libcello.org/learn/a-fat-pointer-library) to get an
overview of how Cello works. You can also peek at the source code, which I'm
told is fairly readable, or ask me any questions you like via e-mail.
* __Can it be used in Production?__
It might be better to try Cello out on a hobby project first. Cello does aim to
be _production ready_, but because it is a hack it has its fair share of
oddities and pitfalls, and if you are working in a team, or to a deadline,
there is much better tooling, support and community for languages such as C++.
* __Is anyone using Cello?__
People have experimented with it, but there is no high profile project I know
of that uses it. Cello is too big and scary a dependency for new C projects if
they want to be portable and easy to maintain.
* __Can I get involved?__
Yes! That would be great. If you do anything with Cello I'd love to know, you
can e-mail me at `contact@theorangeduck.com`, or help with the development at
the [Cello github repo](https://github.com/orangeduck/libCello). Contributions
are very welcome.
* __Who are you?__
Hello! I'm Daniel Holden. You many know me from a
[book I wrote](http://www.buildyourownlisp.com/) or my
[personal website](http://theorangeduck.com/). I also have a rarely updated
[twitter account](https://twitter.com/anorangeduck).
================================================
FILE: TODO.md
================================================
Cello 2.0
=========
Cello REPL
==========
* REPL
- Python prototype
- Parse CPP and extract defines.
- Parse Syntax tree and extract type/variable declarations
- Record those in permanent storage which is added to every file
================================================
FILE: benchmarks/Dict/dict_c.c
================================================
#include <stdio.h>
#include "khash.h"
KHASH_MAP_INIT_STR(str, int)
#define BUF_SIZE 0x10000
#define BLOCK_SIZE 0x100000
int main(int argc, char *argv[])
{
char *buf, **mem = 0;
int ret, max = 1, block_end = 0, curr = 0;
khint_t k;
khash_t(str) *h;
buf = malloc(BUF_SIZE); // string buffer
h = kh_init(str);
mem = malloc(sizeof(void*));
mem[0] = malloc(BLOCK_SIZE); // memory buffer to avoid memory fragments
curr = block_end = 0;
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
k = kh_put(str, h, buf, &ret);
if (ret) { // absent
int l = strlen(buf) + 1;
if (block_end + l > BLOCK_SIZE) {
++curr; block_end = 0;
mem = realloc(mem, (curr + 1) * sizeof(void*));
mem[curr] = malloc(BLOCK_SIZE);
}
memcpy(mem[curr] + block_end, buf, l);
kh_key(h, k) = mem[curr] + block_end;
block_end += l;
kh_val(h, k) = 1;
} else {
++kh_val(h, k);
if (kh_val(h, k) > max) max = kh_val(h, k);
}
}
//printf("%u\t%d\n", kh_size(h), max);
for (ret = 0; ret <= curr; ++ret) free(mem[ret]);
free(mem);
kh_destroy(str, h);
free(buf);
return 0;
}
================================================
FILE: benchmarks/Dict/dict_cello.c
================================================
#include "Cello.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
BUF_SIZE = 0x10000
};
int main(int argc, char *argv[]) {
var h = new(Table, String, Int);
resize(h, 1500000);
int max = 1;
char *buf = malloc(BUF_SIZE);
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
var key = $S(buf);
if (mem(h, key)) {
struct Int* v = get(h, key);
v->val++;
if (max < v->val) { max = v->val; }
} else {
set(h, key, $I(1));
}
}
del(h);
return 0;
}
================================================
FILE: benchmarks/Dict/dict_cpp.cpp
================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <unordered_map>
using namespace std;
struct eqstr {
inline bool operator()(const char *s1, const char *s2) const {
return strcmp(s1, s2) == 0;
}
};
namespace std {
template<>
struct hash<const char *> : public std::unary_function<const char *, size_t> {
size_t operator()(const char *s) const
{
size_t h = *s;
if (h) for (++s ; *s; ++s) h = (h << 5) - h + *s;
return h;
}
};
}
typedef unordered_map<const char*, int, hash<const char*>, eqstr> strhash;
#define BUF_SIZE 0x10000
#define BLOCK_SIZE 0x100000
int main(int argc, char *argv[])
{
char *buf;
int ret, max = 1, block_end = 0, curr = 0;
char **mem;
strhash *h = new strhash;
buf = (char*)malloc(BUF_SIZE); // buffer size
mem = (char**)malloc(sizeof(void*));
mem[0] = (char*)malloc(BLOCK_SIZE); // memory buffer to avoid memory fragments
curr = block_end = 0;
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
strhash::iterator p = h->find(buf);
if (p == h->end()) {
int l = strlen(buf) + 1;
if (block_end + l > BLOCK_SIZE) {
++curr; block_end = 0;
mem = (char**)realloc(mem, (curr + 1) * sizeof(void*));
mem[curr] = (char*)malloc(BLOCK_SIZE);
}
memcpy(mem[curr] + block_end, buf, l);
h->insert(pair<const char*, int>(mem[curr] + block_end, 1));
block_end += l;
} else {
++p->second;
if (max < p->second) max = p->second;
}
}
//printf("%u\t%d\n", h->size(), max);
for (int i = 0; i <= curr; ++i) free(mem[i]);
free(mem); free(buf);
delete h;
return 0;
}
================================================
FILE: benchmarks/Dict/dict_cs.cs
================================================
using System;
using System.Collections.Generic;
class dict_v1 {
static void Main() {
string l;
Dictionary<string, int> h = new Dictionary<string, int>();
int max = 1;
while ((l = Console.ReadLine()) != null) {
int v;
if (h.TryGetValue(l, out v)) {
if (v+1 > max) max = v+1;
h[l] = v+1;
} else h[l] = 1;
}
Console.WriteLine(h.Count);
Console.WriteLine(max);
}
}
================================================
FILE: benchmarks/Dict/dict_d.d
================================================
// This program segfaults at the end of the input file. I think this is a bug
// of GDC. I can use std.stream or std.c.stdio instead, but those modules are
// extremely slow. In the end, I decide to specify the number of lines at the
// command line. Pretty nasty.
import std.stdio, std.string;
void main(string[] args) {
int N = 5000000;
char[] buf;
int[char[]] h;
int max = 1, n = 0;
if (args.length >= 2) N = atoi(args[1]);
while (readln(stdin, buf)) {
int current = ++h[buf];
max = (current > max)? current : max;
if (++n == N) {
writef(h.length); writef("\t"); writefln(max);
}
}
writef(h.length); writef("\t"); writefln(max);
}
================================================
FILE: benchmarks/Dict/dict_go.go
================================================
// Contributed by Pat
package main
import (
"fmt"
"bufio"
"os"
)
func main() {
r := bufio.NewReader(os.Stdin)
h := make(map[string]int, 1e6)
max := 1
for {
b, e := r.ReadSlice('\n')
if e != nil {
break
}
l := string(b)
v := h[l] + 1
h[l] = v
if v > max {
max = v
}
}
fmt.Printf("%d\t%d\n", len(h), max)
}
================================================
FILE: benchmarks/Dict/dict_java.java
================================================
import java.util.HashMap;
import java.io.*;
class dict_java {
public static void main(String[] args) {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> h = new HashMap<String, Integer>();
String l;
int max = 0;
try {
while ((l = stdin.readLine()) != null) {
int x = 1;
if (h.containsKey(l)) {
x = h.get(l) + 1;
h.put(l, x);
if (x > max) max = x;
} else h.put(l, 1);
}
} catch (IOException e) {
}
//System.out.println(h.size()+"\t"+max);
}
}
================================================
FILE: benchmarks/Dict/dict_javascript.js
================================================
var h = {}, n = 0, max = 0;
function processLine (l) {
if (h[l]) {
++h[l];
if (max < h[l]) max = h[l];
} else h[l] = 1, ++n;
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
processLine(line);
})
//print(n, max)
================================================
FILE: benchmarks/Dict/dict_lua.lua
================================================
local h, max, n = {}, 0, 0
for l in io.lines() do
if (h[l]) then h[l] = h[l] + 1
else n, h[l] = n + 1, 1 end
max = max > h[l] and max or h[l]
end
-- print(n, max)
================================================
FILE: benchmarks/Dict/dict_perl.pl
================================================
my (%h, $max);
while (<>) {
next if (++$h{$_} > $max);
$max = $h{$_};
}
print scalar(keys(%h)), "\t$max\n";
================================================
FILE: benchmarks/Dict/dict_python.py
================================================
import sys
def count_duplicates(lines):
h, m = {}, 0
for l in lines:
if (l in h): h[l] += 1
else: h[l] = 1
if (m < h[l]): m = h[l]
return h, m
h, m = count_duplicates(sys.stdin)
# print(len(h), m)
================================================
FILE: benchmarks/Dict/dict_ruby.rb
================================================
h, max = {}, 0
STDIN.each do |l|
if h[l] == nil
h[l] = 1
else
h[l] = h[l] + 1
end
max = h[l] if max < h[l]
end
# puts h.length, max
================================================
FILE: benchmarks/GC/gc_c.c
================================================
#include <stdlib.h>
static void create_objects(int depth) {
void
*i00=malloc(16), *i01=malloc(16), *i02=malloc(16), *i03=malloc(16), *i04=malloc(16),
*i05=malloc(16), *i06=malloc(16), *i07=malloc(16), *i08=malloc(16), *i09=malloc(16),
*i10=malloc(16), *i11=malloc(16), *i12=malloc(16), *i13=malloc(16), *i14=malloc(16),
*i15=malloc(16), *i16=malloc(16), *i17=malloc(16), *i18=malloc(16), *i19=malloc(16),
*i20=malloc(16), *i21=malloc(16), *i22=malloc(16), *i23=malloc(16), *i24=malloc(16),
*i25=malloc(16), *i26=malloc(16), *i27=malloc(16), *i28=malloc(16), *i29=malloc(16),
*i30=malloc(16), *i31=malloc(16), *i32=malloc(16), *i33=malloc(16), *i34=malloc(16);
if (depth == 2) {
return;
}
for (size_t i = 0; i < 10; i++) {
create_objects(depth+1);
}
volatile int noinline = 1;
if (noinline) {
free(i00); free(i01); free(i02); free(i03); free(i04); free(i05);
free(i06); free(i07); free(i08); free(i09); free(i10); free(i11);
free(i12); free(i13); free(i14); free(i15); free(i16); free(i17);
free(i18); free(i19); free(i20); free(i21); free(i22); free(i23);
free(i24); free(i25); free(i26); free(i27); free(i28); free(i29);
free(i30); free(i31); free(i32); free(i34);
}
}
int main(int argc, char** argv) {
for (size_t i = 0; i < 100; i++) {
create_objects(0);
}
}
================================================
FILE: benchmarks/GC/gc_cello.c
================================================
#include "Cello.h"
static void create_objects(int depth) {
var
i00=new(Int), i01=new(Int), i02=new(Int), i03=new(Int), i04=new(Int),
i05=new(Int), i06=new(Int), i07=new(Int), i08=new(Int), i09=new(Int),
i10=new(Int), i11=new(Int), i12=new(Int), i13=new(Int), i14=new(Int),
i15=new(Int), i16=new(Int), i17=new(Int), i18=new(Int), i19=new(Int),
i20=new(Int), i21=new(Int), i22=new(Int), i23=new(Int), i24=new(Int),
i25=new(Int), i26=new(Int), i27=new(Int), i28=new(Int), i29=new(Int),
i30=new(Int), i31=new(Int), i32=new(Int), i33=new(Int), i34=new(Int);
volatile int noinline = 0;
if (noinline) {
show(i00); show(i01); show(i02); show(i03); show(i04); show(i05);
show(i06); show(i07); show(i08); show(i09); show(i10); show(i11);
show(i12); show(i13); show(i14); show(i15); show(i16); show(i17);
show(i18); show(i19); show(i20); show(i21); show(i22); show(i23);
show(i24); show(i25); show(i26); show(i27); show(i28); show(i29);
show(i30); show(i31); show(i32); show(i34);
}
if (depth == 2) {
return;
}
for (size_t i = 0; i < 10; i++) {
create_objects(depth+1);
}
}
int main(int argc, char** argv) {
for (size_t i = 0; i < 100; i++) {
create_objects(0);
}
return 0;
}
================================================
FILE: benchmarks/GC/gc_cpp.cpp
================================================
#include <stdlib.h>
class Int {
int64_t i;
public:
Int() : i(0) {}
};
static void create_objects(int depth) {
Int
*i00=new Int(), *i01=new Int(), *i02=new Int(), *i03=new Int(), *i04=new Int(),
*i05=new Int(), *i06=new Int(), *i07=new Int(), *i08=new Int(), *i09=new Int(),
*i10=new Int(), *i11=new Int(), *i12=new Int(), *i13=new Int(), *i14=new Int(),
*i15=new Int(), *i16=new Int(), *i17=new Int(), *i18=new Int(), *i19=new Int(),
*i20=new Int(), *i21=new Int(), *i22=new Int(), *i23=new Int(), *i24=new Int(),
*i25=new Int(), *i26=new Int(), *i27=new Int(), *i28=new Int(), *i29=new Int(),
*i30=new Int(), *i31=new Int(), *i32=new Int(), *i33=new Int(), *i34=new Int();
if (depth == 2) {
return;
}
for (size_t i = 0; i < 10; i++) {
create_objects(depth+1);
}
volatile int noinline = 1;
if (noinline) {
delete(i00); delete(i01); delete(i02); delete(i03); delete(i04); delete(i05);
delete(i06); delete(i07); delete(i08); delete(i09); delete(i10); delete(i11);
delete(i12); delete(i13); delete(i14); delete(i15); delete(i16); delete(i17);
delete(i18); delete(i19); delete(i20); delete(i21); delete(i22); delete(i23);
delete(i24); delete(i25); delete(i26); delete(i27); delete(i28); delete(i29);
delete(i30); delete(i31); delete(i32); delete(i34);
}
}
int main(int argc, char** argv) {
for (size_t i = 0; i < 100; i++) {
create_objects(0);
}
}
================================================
FILE: benchmarks/GC/gc_java.java
================================================
public final class gc_java {
final public static class Int {
private int value;
Int(int x) {
value = x;
}
}
public static void create_objects(int depth) {
Int i00=new Int(0); Int i01=new Int(0);
Int i02=new Int(0); Int i03=new Int(0);
Int i04=new Int(0); Int i05=new Int(0);
Int i06=new Int(0); Int i07=new Int(0);
Int i08=new Int(0); Int i09=new Int(0);
Int i10=new Int(0); Int i11=new Int(0);
Int i12=new Int(0); Int i13=new Int(0);
Int i14=new Int(0); Int i15=new Int(0);
Int i16=new Int(0); Int i17=new Int(0);
Int i18=new Int(0); Int i19=new Int(0);
Int i20=new Int(0); Int i21=new Int(0);
Int i22=new Int(0); Int i23=new Int(0);
Int i24=new Int(0); Int i25=new Int(0);
Int i26=new Int(0); Int i27=new Int(0);
Int i28=new Int(0); Int i29=new Int(0);
Int i30=new Int(0); Int i31=new Int(0);
Int i32=new Int(0); Int i33=new Int(0);
Int i34=new Int(0);
if (depth == 2) {
return;
}
for (int i = 0; i < 10; i++) {
create_objects(depth+1);
}
}
public static void main(String[] args) {
for (int i=0; i<10000; ++i) {
create_objects(0);
}
}
}
================================================
FILE: benchmarks/GC/gc_javascript.js
================================================
function Int() {
return {val:0}
}
function create_objects(depth) {
var i00=Int(); var i01=Int(); var i02=Int(); var i03=Int(); var i04=Int();
var i05=Int(); var i06=Int(); var i07=Int(); var i08=Int(); var i09=Int();
var i10=Int(); var i11=Int(); var i12=Int(); var i13=Int(); var i14=Int();
var i15=Int(); var i16=Int(); var i17=Int(); var i18=Int(); var i19=Int();
var i20=Int(); var i21=Int(); var i22=Int(); var i23=Int(); var i24=Int();
var i25=Int(); var i26=Int(); var i27=Int(); var i28=Int(); var i29=Int();
var i30=Int(); var i31=Int(); var i32=Int(); var i33=Int(); var i34=Int();
if (depth == 2) {
return;
}
for (var i = 0; i < 10; i++) {
create_objects(depth+1);
}
}
for (var i = 0; i < 10000; i++) {
create_objects(0);
}
================================================
FILE: benchmarks/GC/gc_lua.lua
================================================
function Int ()
return {val=0}
end
function create_objects(depth)
local i00=Int(); local i01=Int(); local i02=Int(); local i03=Int(); local i04=Int();
local i05=Int(); local i06=Int(); local i07=Int(); local i08=Int(); local i09=Int();
local i10=Int(); local i11=Int(); local i12=Int(); local i13=Int(); local i14=Int();
local i15=Int(); local i16=Int(); local i17=Int(); local i18=Int(); local i19=Int();
local i20=Int(); local i21=Int(); local i22=Int(); local i23=Int(); local i24=Int();
local i25=Int(); local i26=Int(); local i27=Int(); local i28=Int(); local i29=Int();
local i30=Int(); local i31=Int(); local i32=Int(); local i33=Int(); local i34=Int();
if (depth == 2) then
return;
end
for i=0,10 do
create_objects(depth+1)
end
end
for i=0, 10000 do
create_objects(0)
end
================================================
FILE: benchmarks/GC/gc_python.py
================================================
class Int:
pass
def create_objects(depth):
i00=Int(); i01=Int(); i02=Int(); i03=Int(); i04=Int();
i05=Int(); i06=Int(); i07=Int(); i08=Int(); i09=Int();
i10=Int(); i11=Int(); i12=Int(); i13=Int(); i14=Int();
i15=Int(); i16=Int(); i17=Int(); i18=Int(); i19=Int();
i20=Int(); i21=Int(); i22=Int(); i23=Int(); i24=Int();
i25=Int(); i26=Int(); i27=Int(); i28=Int(); i29=Int();
i30=Int(); i31=Int(); i32=Int(); i33=Int(); i34=Int();
if depth == 2:
return
for i in range(10):
create_objects(depth+1)
for i in range(10000):
create_objects(0)
================================================
FILE: benchmarks/GC/gc_ruby.rb
================================================
class Int
end
def create_objects(depth)
i00=Int.new; i01=Int.new; i02=Int.new; i03=Int.new; i04=Int.new;
i05=Int.new; i06=Int.new; i07=Int.new; i08=Int.new; i09=Int.new;
i10=Int.new; i11=Int.new; i12=Int.new; i13=Int.new; i14=Int.new;
i15=Int.new; i16=Int.new; i17=Int.new; i18=Int.new; i19=Int.new;
i20=Int.new; i21=Int.new; i22=Int.new; i23=Int.new; i24=Int.new;
i25=Int.new; i26=Int.new; i27=Int.new; i28=Int.new; i29=Int.new;
i30=Int.new; i31=Int.new; i32=Int.new; i33=Int.new; i34=Int.new;
if depth == 2 then
return
end
for i in 0..10
create_objects(depth+1)
end
end
for i in 0..10000
create_objects(0)
end
================================================
FILE: benchmarks/List/list_c.c
================================================
#include "kvec.h"
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
kvec_t(int) x;
kv_init(x);
int n = 10000;
for (int i = 0; i < n; i++) {
kv_push(int, x, rand());
}
for (int i = 0; i < n; i++) {
kv_push(int, x, 0);
int index = rand() % n;
memmove(
&x.a[index+1], &x.a[index+0],
sizeof(int) * ((x.n-1) - index));
x.a[index] = rand();
}
for (int i = 0; i < n; i++) {
int index = rand() % n;
memmove(
&x.a[index+0], &x.a[index+1],
sizeof(int) * ((x.n-1) - index));
kv_pop(x);
}
kv_destroy(x);
return 0;
}
================================================
FILE: benchmarks/List/list_cello.c
================================================
#include "Cello.h"
int main(int argc, char** argv) {
var x = new(Array, Int);
int n = 10000;
for (int i = 0; i < n; i++) {
push(x, $I(rand()));
}
for (int i = 0; i < n; i++) {
push_at(x, $I(rand()), $I(rand() % n));
}
for (int i = 0; i < n; i++) {
pop_at(x, $I(rand() % n));
}
del(x);
return 0;
}
================================================
FILE: benchmarks/List/list_cpp.cpp
================================================
#include <stdlib.h>
#include <vector>
int main(int argc, char** argv) {
std::vector<int> x = std::vector<int>();
int n = 10000;
for (int i = 0; i < n; i++) {
x.push_back(rand());
}
for (int i = 0; i < n; i++) {
x.insert(x.begin()+(rand() % n), rand());
}
for (int i = 0; i < n; i++) {
x.erase(x.begin()+(rand() % n));
}
return 0;
}
================================================
FILE: benchmarks/List/list_java.java
================================================
import java.util.ArrayList;
import java.util.Random;
import java.io.*;
class list_java {
public static void main(String[] args) {
ArrayList<Integer> x = new ArrayList<Integer>();
Random rand = new Random();
int n = 10000;
for (int i = 0; i < n; i++) {
x.add(rand.nextInt());
}
for (int i = 0; i < n; i++) {
x.add(rand.nextInt(n), rand.nextInt());
}
for (int i = 0; i < n; i++) {
x.remove(rand.nextInt(n));
}
}
}
================================================
FILE: benchmarks/List/list_javascript.js
================================================
var l = []
var n = 10000
for (var i = 0; i < n; i++) {
l.push(Math.floor((Math.random() * 32767) + 0))
}
for (var i = 0; i < n; i++) {
l.splice(
Math.floor((Math.random() * n) + 0), 0,
Math.floor((Math.random() * 32767) + 0))
}
for (var i = 0; i < n; i++) {
l.pop(Math.floor((Math.random() * n) + 0))
}
================================================
FILE: benchmarks/List/list_lua.lua
================================================
require "math"
l = {}
n = 10000
for i=1,n do
l[i] = math.random(0, 32767)
end
for i=1,n do
table.insert(l,
math.random(1, n),
math.random(0, 32767))
end
for i=1,n do
table.remove(l, math.random(1, n))
end
================================================
FILE: benchmarks/List/list_python.py
================================================
import random
l = []
n = 10000
random.seed(123)
for i in xrange(n):
l.append(random.randint(0, 32767))
for i in xrange(n):
l.insert(
random.randint(0, n),
random.randint(0, 32767))
for i in xrange(n):
l.pop(random.randint(0, n))
del l
================================================
FILE: benchmarks/List/list_ruby.rb
================================================
l = []
n = 10000
n.times {
l.push(rand())
}
n.times {
l.insert(rand(n), rand())
}
n.times {
l.delete_at(rand(n))
}
================================================
FILE: benchmarks/Map/dict.lua
================================================
local prv = {}
local pub = {}
dict = pub
function prv.rot_less(node)
local R = node.greater
local M = R.less
if R.weight == 0 then
node.weight, R.weight = 1, -1
else
node.weight, R.weight = 0, 0
end
if M then M.parent = node end
node.greater, node.parent, R.less, R.parent =
M, R, node, node.parent
return R
end
function prv.rot_greater(node)
local L = node.less
local M = L.greater
if L.weight == 0 then
node.weight, L.weight = -1, 1
else
node.weight, L.weight = 0, 0
end
if M then M.parent = node end
node.less, node.parent, L.greater, L.parent = M, L, node, node.parent
return L
end
function prv.rot2_less(node)
local R = node.greater
local M = R.less
local ML, MR = M.less, M.greater
if M.weight == 0 then
node.weight, R.weight = 0, 0
elseif M.weight == -1 then
node.weight, R.weight, M.weight = 0, 1, 0
else
node.weight, R.weight, M.weight = -1, 0, 0
end
if ML then ML.parent = node end
if MR then MR.parent = R end
node.greater, node.parent, M.less, M.greater, M.parent, R.less, R.parent =
ML, M, node, R, node.parent, MR, M
return M
end
function prv.rot2_greater(node)
local L = node.less
local M = L.greater
local ML, MR = M.less, M.greater
if M.weight == 0 then
node.weight, L.weight = 0, 0
elseif M.weight == -1 then
node.weight, L.weight, M.weight = 1, 0, 0
else
node.weight, L.weight, M.weight = 0, -1, 0
end
if ML then ML.parent = L end
if MR then MR.parent = node end
node.less, node.parent, M.greater, M.less, M.parent, L.greater, L.parent =
MR, M, node, L, node.parent, ML, M
return M
end
function prv.rebalance(dict, node)
local p, n, short = node.parent
if node.weight == -2 then
local w = node.less.weight
if w == 1 then
short = 1
n = %prv.rot2_greater(node)
else
short = w == -1
n = %prv.rot_greater(node)
end
elseif node.weight == 2 then
local w = node.greater.weight
if w == -1 then
short = 1
n = %prv.rot2_less(node)
else
short = w == 1
n = %prv.rot_less(node)
end
elseif node.weight ~= 0 or not p then
return
else
return p.less == node and 1 or -1
end
if not p then
dict.root = n
elseif node == p.less then
p.less = n
return short and 1
else
p.greater = n
return short and -1
end
end
local node_tag = newtag()
function prv.node(record, parent)
local n = {
record = record,
weight = 0,
parent = parent,
}
settag(n, %node_tag)
return n
end
local dict_tag = newtag()
local dict_meta = {}
settagmethod(dict_tag, "index", function(_, index)
return %dict_meta[index]
end)
function dict_meta:insert(record)
local n, node = self.root, %prv.node(record)
if not n then
self.root = node
else
local ro = self.record_order
local p, t
repeat
if n.weight ~= 0 then t = n end
p = n
if ro(record, n.record) < 0 then
n = n.less
if not n then
node.parent = p
n = node
p.less = n
break
end
else
n = n.greater
if not n then
node.parent = p
n = node
p.greater = n
break
end
end
until nil
while p ~= t do
p.weight = n == p.less and -1 or 1
p, n = p.parent, p
end
if t then
if n == t.less then
t.weight = t.weight - 1
else
t.weight = t.weight + 1
end
%prv.rebalance(self, t)
end
end
self.n = self.n + 1
return node
end
function dict_meta:erase(node)
assert(tag(node) == %node_tag, "erase takes an iterator!")
local p, n, swap = node.parent
if node.less then
if node.greater then
-- both children
p, n = node, node.greater
while n.less do
p, n = n, n.less
end
swap, node, n = node, n, n.greater
else
-- only less child
n = node.less
end
elseif node.greater then
-- only greater child
n = node.greater
else
-- no children
-- n = nil
end
if n then n.parent = p end
self.n = self.n - 1
if not p then
self.root = n
return
end
if p.greater == node then
p.greater = n
p.weight = p.weight - 1
else
p.less = n
p.weight = p.weight + 1
end
if swap then
local sl, sg, sp = swap.less, swap.greater, swap.parent
node.weight, node.parent, node.less, node.greater =
swap.weight, sp, sl, sg
if sl then sl.parent = node end
if sg then sg.parent = node end
if not sp then
self.root = node
elseif sp.less == swap then
sp.less = node
else
sp.greater = node
end
if p == swap then p = node end
end
local w
p, w = p.parent, %prv.rebalance(self, p)
while w do
p.weight = p.weight + w
p, w = p.parent, %prv.rebalance(self, p)
end
end
function dict_meta:find(key)
local n, t = self.root
local ko = self.key_order
while n do
local ord = ko(key, n.record)
if ord > 0 then
n = n.greater
elseif ord < 0 then
n = n.less
else
t, n = n, n.less
end
end
if t then
return t.record, t
end
end
function dict_meta:lwb(key)
local n, t = self.root
local ko = self.key_order
while n do
if ko(key, n.record) > 0 then
n = n.greater
else
t, n = n, n.less
end
end
if t then
return t.record, t
end
end
function dict_meta:upb(key)
local n, t = self.root
local ko = self.key_order
while n do
if ko(key, n.record) < 0 then
t, n = n, n.less
else
n = n.greater
end
end
if t then
return t.record, t
end
end
function dict_meta:next(node)
local n
if node then
assert(tag(node) == %node_tag, "next takes an iterator")
n = node.greater
elseif self.root then
n = self.root
else
return
end
if n then
repeat
node, n = n, n.less
until not n
return node.record, node
end
repeat
n, node = node, node.parent
until not node or node.less == n
if node then
return node.record, node
end
end
function dict_meta:prev(node)
local n
if node then
assert(tag(node) == %node_tag, "prev takes an iterator")
n = node.less
elseif self.root then
n = self.root
else
return
end
if n then
repeat
node, n = n, n.greater
until not n
return node.record, node
end
repeat
n, node = node, node.parent
until not node or node.greater == n
if node then
return node.record, node
end
end
function dict_meta:first()
return self:next()
end
function dict_meta:last()
return self:prev()
end
function pub.create(record_order, key_order)
local d = {
record_order = record_order or %pub.cmp,
key_order = key_order or record_order or %pub.cmp,
n = 0,
}
settag(d, %dict_tag)
return d
end
function pub.record(node)
assert(tag(node) == %node_tag, "record takes an iterator")
return node.record
end
function pub.cmp(a, b)
return a < b and -1 or (b < a and 1 or 0)
end
================================================
FILE: benchmarks/Map/map_c.c
================================================
#include <stdio.h>
#include "kbtree.h"
typedef struct {
char *key;
int count;
} elem_t;
#define elem_cmp(a, b) (strcmp((a).key, (b).key))
KBTREE_INIT(str, elem_t, elem_cmp)
#define BUF_SIZE 0x10000
#define BLOCK_SIZE 0x100000
int main(int argc, char *argv[])
{
char *buf, **mem = 0;
int ret, max = 1, block_end = 0, curr = 0;
kbtree_t(str) *h;
h = kb_init(str, KB_DEFAULT_SIZE);
buf = malloc(BUF_SIZE); // string buffer
mem = malloc(sizeof(void*));
mem[0] = malloc(BLOCK_SIZE); // memory buffer to avoid memory fragments
curr = block_end = 0;
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
elem_t t = { buf, 1 };
elem_t *p = kb_getp(str, h, &t);
if (!p) {
int l = strlen(buf) + 1;
if (block_end + l > BLOCK_SIZE) {
++curr; block_end = 0;
mem = realloc(mem, (curr + 1) * sizeof(void*));
mem[curr] = malloc(BLOCK_SIZE);
}
memcpy(mem[curr] + block_end, buf, l);
t.key = mem[curr] + block_end;
t.count = 1;
kb_putp(str, h, &t);
block_end += l;
} else {
p->count++;
if (p->count > max) max = p->count;
}
}
//printf("%u\t%d\n", kh_size(h), max);
for (ret = 0; ret <= curr; ++ret) free(mem[ret]);
free(mem);
kb_destroy(str, h);
free(buf);
return 0;
}
================================================
FILE: benchmarks/Map/map_cello.c
================================================
#include "Cello.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
BUF_SIZE = 0x10000
};
int main(int argc, char *argv[]) {
var m = new(Tree, String, Int);
int max = 1;
char *buf = malloc(BUF_SIZE);
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
var key = $S(buf);
if (mem(m, key)) {
struct Int* v = get(m, key);
v->val++;
if (max < v->val) { max = v->val; }
} else {
set(m, key, $I(1));
}
}
del(m);
return 0;
}
================================================
FILE: benchmarks/Map/map_cpp.cpp
================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <map>
using namespace std;
struct eqstr {
inline bool operator()(const char *s1, const char *s2) const {
return strcmp(s1, s2) == 0;
}
};
typedef map<const char*, int, eqstr> strmap;
#define BUF_SIZE 0x10000
#define BLOCK_SIZE 0x100000
int main(int argc, char *argv[])
{
char *buf;
int ret, max = 1, block_end = 0, curr = 0;
char **mem;
strmap *m = new strmap;
buf = (char*)malloc(BUF_SIZE); // buffer size
mem = (char**)malloc(sizeof(void*));
mem[0] = (char*)malloc(BLOCK_SIZE); // memory buffer to avoid memory fragments
curr = block_end = 0;
while (!feof(stdin)) {
fgets(buf, BUF_SIZE, stdin);
strmap::iterator p = m->find(buf);
if (p == m->end()) {
int l = strlen(buf) + 1;
if (block_end + l > BLOCK_SIZE) {
++curr; block_end = 0;
mem = (char**)realloc(mem, (curr + 1) * sizeof(void*));
mem[curr] = (char*)malloc(BLOCK_SIZE);
}
memcpy(mem[curr] + block_end, buf, l);
m->insert(pair<const char*, int>(mem[curr] + block_end, 1));
block_end += l;
} else {
++p->second;
if (max < p->second) max = p->second;
}
}
//printf("%u\t%d\n", h->size(), max);
for (int i = 0; i <= curr; ++i) free(mem[i]);
free(mem); free(buf);
delete m;
return 0;
}
================================================
FILE: benchmarks/Map/map_cs.cs
================================================
using System;
using System.Collections.Generic;
class dict_v1 {
static void Main() {
string l;
SortedSet<string, int> m = new SortedSet<string, int>();
int max = 1;
while ((l = Console.ReadLine()) != null) {
int v;
if (m.TryGetValue(l, out v)) {
if (v+1 > max) max = v+1;
m[l] = v+1;
} else m[l] = 1;
}
Console.WriteLine(m.Count);
Console.WriteLine(max);
}
}
================================================
FILE: benchmarks/Map/map_d.d
================================================
// This program segfaults at the end of the input file. I think this is a bug
// of GDC. I can use std.stream or std.c.stdio instead, but those modules are
// extremely slow. In the end, I decide to specify the number of lines at the
// command line. Pretty nasty.
import std.stdio, std.string;
void main(string[] args) {
int N = 5000000;
char[] buf;
int[char[]] h;
int max = 1, n = 0;
if (args.length >= 2) N = atoi(args[1]);
while (readln(stdin, buf)) {
int current = ++h[buf];
max = (current > max)? current : max;
if (++n == N) {
writef(h.length); writef("\t"); writefln(max);
}
}
writef(h.length); writef("\t"); writefln(max);
}
================================================
FILE: benchmarks/Map/map_go.go
================================================
// Contributed by Pat
package main
import (
"fmt"
"bufio"
"os"
)
func main() {
r := bufio.NewReader(os.Stdin)
h := make(map[string]int, 1e6)
max := 1
for {
b, e := r.ReadSlice('\n')
if e != nil {
break
}
l := string(b)
v := h[l] + 1
h[l] = v
if v > max {
max = v
}
}
fmt.Printf("%d\t%d\n", len(h), max)
}
================================================
FILE: benchmarks/Map/map_java.java
================================================
import java.util.TreeMap;
import java.io.*;
class map_java {
public static void main(String[] args) {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
TreeMap<String, Integer> h = new TreeMap<String, Integer>();
String l;
int max = 0;
try {
while ((l = stdin.readLine()) != null) {
int x = 1;
if (h.containsKey(l)) {
x = h.get(l) + 1;
h.put(l, x);
if (x > max) max = x;
} else h.put(l, 1);
}
} catch (IOException e) {
}
//System.out.println(h.size()+"\t"+max);
}
}
================================================
FILE: benchmarks/Map/map_javascript.js
================================================
var RBTree = require('bintrees').RBTree;
var strcmp = function (a, b) { return a.localeCompare(b); };
var h = new RBTree(strcmp), n = 0, max = 0;
function processLine (l) {
var val = h.find(l)
if (val) {
h.insert(val+1);
if (max < val+1) max = val+1;
} else h.insert(l, 1), ++n;
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
processLine(line);
})
//print(n, max)
================================================
FILE: benchmarks/Map/map_lua.lua
================================================
require 'Map/redblack'
local h = redblack.newTree()
local max = 0
for l in io.lines() do
local c = redblack.find(h, l)
if (c) then
-- This Red black doesn't support value types so whatever
redblack.insert(h, l)
-- max = max > c and max or c
else
redblack.insert(h, l)
end
end
-- print(n, max)
================================================
FILE: benchmarks/Map/map_perl.pl
================================================
my (%h, $max);
while (<>) {
next if (++$h{$_} > $max);
$max = $h{$_};
}
print scalar(keys(%h)), "\t$max\n";
================================================
FILE: benchmarks/Map/map_python.py
================================================
import sys
from bintrees import RBTree
def count_duplicates(lines):
h, m = RBTree(), 0
for l in lines:
if (l in h): h[l] += 1
else: h[l] = 1
if (m < h[l]): m = h[l]
return h, m
h, m = count_duplicates(sys.stdin)
# print(len(h), m)
================================================
FILE: benchmarks/Map/map_ruby.rb
================================================
require 'rbtree'
h, max = RBTree[], 0
STDIN.each do |l|
if h[l] == nil
h[l] = 1
else
h[l] = h[l] + 1
end
max = h[l] if max < h[l]
end
# puts h.length, max
================================================
FILE: benchmarks/Map/rb.lua
================================================
---------------------------------------
--
-- rb.lua
-- 20110212
--
-- from cormen 2nd edition
--
---------------------------------------
--[[
node = {
k; -- key
red; -- true or false
l; -- left subtree
r; -- right subtree
p; -- parent
data; -- for the client
}
tree = {
root;
NIL; -- sentinel node: parent of root / leaves
}
--]]
-- used for the simetric operations
-- d is either 'left'/'right' or true/false (or error !)
-- returns 'l','r' or 'r','l'
local function direction(d)
if d == 'left' or d == true then
return 'l','r','left','right'
elseif d == 'right' or d == false then
return 'r','l','right','left'
else
error("bad argument to 'direction' : either 'left' or 'right'")
end
end
local function new()
local NIL = {}
NIL.p = NIL
NIL.l = NIL
NIL.r = NIL
return {root = NIL, NIL=NIL}
end
-- names of variables are consistent with minimum
local function edge(x, NIL, d)
local L = direction(d)
while x[L] ~= NIL do
x = x[L]
end
return x
end
-- names of variables are consistent with successor (!)
local function next(x, NIL, d)
local _, R = direction(d)
if x[R] ~= NIL then
return edge(x[R], NIL, d)
end
local y = x.p
while y ~= NIL and x == y[R] do
x = y
y = y.p
end
return y
end
local function search(x, k, NIL)
while x ~= NIL and x.k ~= k do
if k < x.k then
x = x.l
else
x = x.r
end
end
return x
end
-- names of variables are consistent with left rotation
local function rotate (t,x,d)
local L,R = direction(d)
local y = x[R]
x[R] = y[L]
if y[L] ~= t.NIL
then y[L].p = x end
y.p = x.p
if x.p == t.NIL
then t.root = y
else if x == x.p[L]
then x.p[L] = y
else x.p[R] = y end end
y[L] = x
x.p = y
end
local function fixinsert(t,z)
local n = z
while z.p.red do
local L,R,LEFT,RIGHT = direction(z.p == z.p.p.l)
local y = z.p.p[R]
if y.red then
z.p.red = nil
y.red = nil
z.p.p.red = true
z = z.p.p
else
if z == z.p[R] then
z = z.p
rotate(t,z,LEFT)
end
z.p.red = nil
z.p.p.red = true
rotate(t,z.p.p,RIGHT)
end
end
t.root.red = nil
return n
end
local function insert(t,k,data)
local NIL = t.NIL
local y = NIL
local x = t.root
while x ~= NIL
do y = x
if k == x.k then return x end
if k < x.k
then x = x.l
else x = x.r end end
local z = {k=k,data=data}
z.p = y
if y == NIL
then t.root = z
else
if k == y.k then return y end
if k < y.k
then y.l = z
else y.r = z end end
z.l = NIL
z.r = NIL
z.red = true
z.data = data
return fixinsert(t,z)
end
local function fixdelete(t, x)
local y,z,w
while x ~= t.root and not x.red do
local L,R,LEFT,RIGHT = direction(x == x.p.l)
w = x.p[R]
if w.red then
w.red = nil
x.p.red = true
rotate(t, x.p, LEFT)
w = x.p[R]
end
if not w[L].red and not w[R].red then
w.red = true
x = x.p
else
if not w[R].red then
w[L].red = nil
w.red = true
rotate(t, w, RIGHT)
w = x.p[R]
end
w.red = x.p.red
x.p.red = nil
w[R].red = nil
rotate(t, x.p, LEFT)
x = t.root
end
end
x.red = nil
end
local function delete(t, z)
local NIL = t.NIL
local x,y
if z.l == NIL or z.r == NIL
then y = z
else y = next(z, NIL, 'left') end
if y.l ~= NIL
then x = y.l
else x = y.r end
x.p = y.p
if y.p == NIL
then t.root = x
else if y == y.p.l
then y.p.l = x
else y.p.r = x end end
if y ~= z
then z.k = y.k
z.data = y.data end
if not y.red
then fixdelete(t, x) end
return y
end
return {
new = new;
minimum = function(x,NIL) return edge(x,NIL,'left') end;
maximum = function(x,NIL) return edge(x,NIL,'right') end;
predecessor = function(x,NIL) return next(x,NIL,'right') end;
successor = function(x,NIL) return next(x,NIL,'left') end;
search = search;
insert = insert;
delete = delete;
}
================================================
FILE: benchmarks/Map/redblack.lua
================================================
--------------------------------------------------------------------------------
-- Copyright (C) 2014, Greg Johnson.
-- Released under the terms of the GNU GPL v2.0.
--------------------------------------------------------------------------------
--[[
This is a lua implementation of red black trees.
Here are the provided operations:
- create a new tree
- insert a data element
- delete a data element
- find a data element
- iterate over the data elements
A red black tree is a binary search tree in which each node is marked
as a red node or a black node. The tree satisfies the following two
properties, which together guarantee that insert, delete, and find
operations are all O(logN):
Red property: Red nodes do not have red parents.
Black property: Siblings have the same maximum black height.
(The maximum black height of a node is the maximum number of black nodes
on any simple path starting at the node and descending into its subtree.)
Data values are any lua values that support comparison via "<", including
tables with metatables containing the "__lt" method.
Usage:
require 'redblack'
local tree = redblack.newTree()
redblack.insert(tree, 10)
redblack.insert(tree, 20)
for value in redblack.iterate(tree) do
print(value)
end
print(redblack.find(tree, 10)) -- expect 10
redblack.delete(tree, 10)
redblack.delete(tree, 20)
print(redblack.find(tree, 10) ~= nil) -- expect false
--]]
local delete, deleteNode, farNephew, findNode, first, grandparent, insert
local insertIntoSortedPosition, insideChild, isBlackNode, isInsideChild
local isLeftChild, isRedNode, isRightChild, isRootNode, iterate
local leftChild, ensureFarNephewIsRed, ensureOutsideChild, makeRootNode
local ensureSiblingIsBlack, nearNephew, newNode, newTree, outsideChild
local parent, restoreBlackProperty, restoreRedProperty, rightChild
local rotateUp, rotateUpBlackNode, setChild, sibling, successor, swapColors
local swapWithSuccessor, uncle, violatesBlackProperty, violatesRedProperty
local getChildOrNil, getOnlyChild, find, ensureLeafOrParentOfOneLeaf
------------------------------- public functions -------------------------------
function newTree()
return { childList = {} }
end
-- insert a node into the tree; data values must be comparable using "<".
--
function insert(tree, data)
local insertedNode = insertIntoSortedPosition(tree, tree.root, data)
if violatesRedProperty(insertedNode) then
restoreRedProperty(tree, insertedNode)
end
end
-- delete a node from the tree; data values must be comparable using "<".
--
function delete(tree, data)
local deleteMe = findNode(tree.root, data)
if deleteMe == nil then return end
deleteMe = ensureLeafOrParentOfOneLeaf(deleteMe)
if not isRootNode(deleteMe) and not isRedNode(deleteMe) then
deleteMe.color = 'white' -- to satisfy pre-condition of restoreBlackProperty()
restoreBlackProperty(tree, deleteMe)
end
deleteNode(tree, deleteMe)
end
function find(tree, data)
local node = findNode(tree.root, data)
return node and node.data
end
function iterate(xTree)
local f = function(s, var)
local result = s.returnMe
s.returnMe = successor(s.returnMe)
return result and result.data
end
return f, { returnMe = first(xTree.root) }, nil
end
----------------------------- end public functions -----------------------------
-- Node "fixMe" is red and has a red parent, violating the red property.
-- Other than that, all nodes in the tree satisfy the red and black properties.
--
-- Upon return, the red property is restored for all nodes in the tree.
--
function restoreRedProperty(tree, fixMe)
-- base case 1:
if isRootNode(parent(fixMe)) then
parent(fixMe).color = 'black'
-- base case 2:
elseif not isRedNode(uncle(fixMe)) then
-- rotateUp changes color of outside child's parent.
-- So, if fixMe is outside child, then rotateUp(parent of fixMe) will fix red violation.
--
-- (rotateUp requires a red node with black sibling as input)
fixMe = ensureOutsideChild(tree, fixMe)
rotateUp(tree, parent(fixMe))
-- inductive case:
else
parent(fixMe).color = 'black'
uncle(fixMe).color = 'black'
grandparent(fixMe).color = 'red'
if violatesRedProperty(grandparent(fixMe)) then
restoreRedProperty(tree, grandparent(fixMe))
end
end
end
-- Node fixMe has max black height one less than its sibling, violating the black property.
-- Other than that, all nodes in the tree satisfy the red and black properties.
-- (This algorithm also requires that fixMe not be a red node.)
--
-- Upon return, the black property is restored for all nodes in the tree.
--
-- (Also, upon return the parent of fixMe (if it exists) is black;
-- this fact is used to slightly simplify the delete algorithm.)
--
function restoreBlackProperty(tree, fixMe)
ensureSiblingIsBlack(tree, fixMe)
-- base case 1:
if isRedNode(nearNephew(fixMe)) or isRedNode(farNephew(fixMe)) then
-- In this case we can treat parent(fixMe) as root of a tree; no recursion will be necessary.
-- rotateUpBlackNode(sibling) will swap max black heights of root's two subtrees.
-- rotate operation will make far nephew a child of root and uncle of fixMe.
-- If we ensure that far nephew is red, we will be able to increase its max
-- black height by simply changing its color to black.
ensureFarNephewIsRed(fixMe)
rotateUpBlackNode(tree, sibling(fixMe))
uncle(fixMe).color = 'black'
else
-- Fix black property violation by reducing sibling's max black height. (This also
-- reduces max black height of parent, potentially giving parent a black violation.)
sibling(fixMe).color = 'red'
-- base case 2:
if isRedNode(parent(fixMe)) then
parent(fixMe).color = 'black'
-- inductive case:
elseif not isRootNode(parent(fixMe)) then
restoreBlackProperty(tree, parent(fixMe))
end
end
end
----------------------------- rotateUp operations ------------------------------
-- pre-condition: redNode must be red and must not have a red sibling.
-- This operation preserves the red and black properties of the tree and the
-- in-order traversal of the tree.
--
-- orig_parent (b) node (b)
-- | |
-- +----+----+ ===> +----+----+
-- | | | |
-- node (r) t3 t1 orig_parent (r)
-- | |
-- +--+--+ +--+--+
-- | | | |
-- t1 t2 t2 t3
--
function rotateUp(tree, redNode)
assert(parent(redNode))
swapColors(redNode, parent(redNode))
local leftChild = isLeftChild(redNode)
local p = parent(redNode)
local gp = grandparent(redNode)
setChild(tree, p, insideChild(redNode), leftChild)
setChild(tree, gp, redNode, isLeftChild(p))
setChild(tree, redNode, p, not leftChild)
end
-- pre-condition: blackNode must be black and must not have a red outside child.
-- This function preserves the red property and the in-order traversal of the tree,
-- but it violates the black property:
--
-- if we consider parent(blackNode) to be the root of a subtree,
-- rotateUpBlackNode(node) swaps max black heights of root's two subtrees.
--
-- (This function is identical to rotateUp(), except for the pre-conditions)
--
function rotateUpBlackNode(tree, blackNode)
rotateUp(tree, blackNode)
end
--------------------------- end rotateUp operations ----------------------------
------------------------------- iterator support -------------------------------
function first(xNode)
while leftChild(xNode) do
xNode = leftChild(xNode)
end
return xNode
end
function successor(xNode)
local result = first(rightChild(xNode))
if result == nil then
while isRightChild(xNode) do
xNode = parent(xNode)
end
result = parent(xNode)
end
return result
end
----------------------------- end iterator support -----------------------------
------------------------------ familial relations ------------------------------
function parent(node)
return node and node.parent
end
function sibling(node)
if isLeftChild(node) then return rightChild(parent(node))
elseif isRightChild(node) then return leftChild(parent(node))
else return nil
end
end
function insideChild(node)
if isLeftChild(node) then return node.childList[2]
elseif isRightChild(node) then return node.childList[1]
else return nil
end
end
function outsideChild(node)
if isLeftChild(node) then return node.childList[1]
elseif isRightChild(node) then return node.childList[2]
else return nil
end
end
function grandparent(node)
return parent(parent(node))
end
function uncle(node)
return sibling(parent(node))
end
function nearNephew(node)
return insideChild(sibling(node))
end
function farNephew(node)
return outsideChild(sibling(node))
end
function getOnlyChild(node)
return (node.childList[1] or node.childList[2])
end
function isInsideChild(node)
return isLeftChild(parent(node)) and isRightChild(node)
or isRightChild(parent(node)) and isLeftChild(node)
end
function ensureOutsideChild(tree, node)
if isInsideChild(node) then
rotateUp(tree, node)
node = outsideChild(node)
end
return node
end
function leftChild(node)
return node and node.childList[1]
end
function rightChild(node)
return node and node.childList[2]
end
function isLeftChild(child)
return child and child == leftChild(parent(child))
end
function isRightChild(child)
return child and child == rightChild(parent(child))
end
function setChild(tree, parentNode, childNode, makeLeftChild)
if parentNode == nil then
tree.root = childNode
elseif makeLeftChild then
parentNode.childList[1] = childNode
else
parentNode.childList[2] = childNode
end
if childNode ~= nil then
childNode.parent = parentNode
end
return childNode
end
function isRootNode(node)
return node and node.parent == nil
end
function makeRootNode(tree, node)
tree.root = node
return node
end
---------------------------- end familial relations ----------------------------
------------------------------ support functions -------------------------------
function violatesRedProperty(node)
return isRedNode(node) and isRedNode(parent(node))
end
function findNode(subtreeRoot, data)
if subtreeRoot == nil then
return nil
elseif data < subtreeRoot.data then
return findNode(subtreeRoot.childList[1], data)
elseif subtreeRoot.data < data then
return findNode(subtreeRoot.childList[2], data)
else
return subtreeRoot
end
end
function insertIntoSortedPosition(tree, subtreeRoot, xData)
if subtreeRoot == nil then
return makeRootNode(tree, newNode(xData))
else
local childIndex = (xData < subtreeRoot.data and 1 or 2)
if subtreeRoot.childList[childIndex] == nil then
return setChild(tree,
subtreeRoot,
newNode(xData),
childIndex == 1)
else
return insertIntoSortedPosition(tree,
subtreeRoot.childList[childIndex],
xData)
end
end
end
function newNode(xData)
local node = { data = xData, color = 'red', childList = {} }
return node
end
function isBlackNode(node)
return node and node.color == 'black'
end
function isRedNode(node)
return node and node.color == 'red'
end
function ensureLeafOrParentOfOneLeaf(deleteMe)
if deleteMe.childList[1] ~= nil and deleteMe.childList[2] ~= nil then
deleteMe = swapWithSuccessor(deleteMe)
end
return deleteMe
end
function swapColors(node1, node2)
node1.color, node2.color = node2.color, node1.color
end
function ensureSiblingIsBlack(tree, node)
if isRedNode(sibling(node)) then
rotateUp(tree, sibling(node))
end
end
function ensureFarNephewIsRed(tree, node)
if isBlackNode(farNephew(node)) then
rotateUp(tree, nearNephew(node))
end
end
function swapWithSuccessor(deleteMe)
local succ = successor(deleteMe)
deleteMe.data, succ.data = succ.data, deleteMe.data
return succ
end
function getChildOrNil(node)
return (node and (node.childList[1] or node.childList[2]))
end
function deleteNode(tree, deleteMe)
assert(deleteMe ~= nil
and (deleteMe.childList[1] == nil or deleteMe.childList[2] == nil))
setChild(tree,
parent(deleteMe),
getChildOrNil(deleteMe),
isLeftChild(deleteMe))
end
---------------------------- end support functions -----------------------------
------------------------- support for testing redblack -------------------------
local function printNode(node)
io.write(tostring(node))
io.write('<c1: ', tostring(node.childList[1]), '>')
io.write(' <c2: ', tostring(node.childList[2]), '>')
io.write(' <color: ', tostring(node.color), '>')
io.write(' <data: ', tostring(node.data), '>')
--for k,v in pairs(node) do
-- io.write(' <' .. tostring(k) .. ': ' .. tostring(v) .. '>')
--end
print()
end
local function printTree(tree, depth)
if tree == nil then return end
if tree.root ~= nil then tree = tree.root end
if depth == nil then depth = 0 end
if depth == 0 then print() end
printTree(tree.childList[1], depth+1)
for i = 1, depth do io.write(" ") end
printNode(tree)
printTree(tree.childList[2], depth+1)
if depth == 0 then print() end
end
testredblack = {
insertIntoSortedPosition = insertIntoSortedPosition,
printNode = printNode,
printTree = printTree,
}
----------------------- end support for testing redblack -----------------------
redblack = {
newTree = newTree,
insert = insert,
delete = delete,
iterate = iterate,
find = find,
}
================================================
FILE: benchmarks/Matmul/matmul_c.c
================================================
// Writen by Attractive Chaos; distributed under the MIT license
#include <stdlib.h>
#include <stdio.h>
double **mm_init(int n)
{
double **m;
int i;
m = (double**)malloc(n * sizeof(void*));
for (i = 0; i < n; ++i)
m[i] = calloc(n, sizeof(double));
return m;
}
void mm_destroy(int n, double **m)
{
int i;
for (i = 0; i < n; ++i) free(m[i]);
free(m);
}
double **mm_gen(int n)
{
double **m, tmp = 1. / n / n;
int i, j;
m = mm_init(n);
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
m[i][j] = tmp * (i - j) * (i + j);
return m;
}
// better cache performance by transposing the second matrix
double **mm_mul(int n, double *const *a, double *const *b)
{
int i, j, k;
double **m, **c;
m = mm_init(n); c = mm_init(n);
for (i = 0; i < n; ++i) // transpose
for (j = 0; j < n; ++j)
c[i][j] = b[j][i];
for (i = 0; i < n; ++i) {
double *p = a[i], *q = m[i];
for (j = 0; j < n; ++j) {
double t = 0.0, *r = c[j];
for (k = 0; k < n; ++k)
t += p[k] * r[k];
q[j] = t;
}
}
mm_destroy(n, c);
return m;
}
int main(int argc, char *argv[])
{
int n = 300;
double **a, **b, **m;
n = (n/2) * 2;
a = mm_gen(n); b = mm_gen(n);
m = mm_mul(n, a, b);
//fprintf(stderr, "%lf\n", m[n/2][n/2]);
mm_destroy(n, a); mm_destroy(n, b); mm_destroy(n, m);
return 0;
}
================================================
FILE: benchmarks/Matmul/matmul_cello.c
================================================
#include "Cello.h"
struct Matrix {
size_t n;
double** d;
};
static void Matrix_New(var self, var args) {
struct Matrix* m = self;
m->n = c_int(get(args, $I(0)));
m->d = malloc(m->n * sizeof(double*));
for (int i = 0; i < m->n; ++i) {
m->d[i] = calloc(m->n, sizeof(double));
}
}
static void Matrix_Del(var self) {
struct Matrix* m = self;
for (int i = 0; i < m->n; ++i) free(m->d[i]);
free(m->d);
}
static var Matrix = Cello(Matrix, Instance(New, Matrix_New, Matrix_Del));
static struct Matrix* Matrix_Gen(int n) {
struct Matrix* m = new(Matrix, $I(n));
double tmp = 1.0 / n / n;
for (int i = 0; i < m->n; ++i) {
for (int j = 0; j < m->n; ++j) {
m->d[i][j] = tmp * (i - j) * (i + j);
}
}
return m;
}
static var Matrix_Mul(var m0, var m1) {
struct Matrix* a = m0;
struct Matrix* b = m1;
struct Matrix* m = new(Matrix, $I(a->n));
struct Matrix* c = new(Matrix, $I(a->n));
for (int i = 0; i < m->n; ++i) {
for (int j = 0; j < m->n; ++j) {
c->d[i][j] = b->d[j][i];
}
}
for (int i = 0; i < m->n; ++i) {
double *p = a->d[i], *q = m->d[i];
for (int j = 0; j < m->n; ++j) {
double t = 0.0, *r = c->d[j];
for (int k = 0; k < m->n; ++k) {
t += p[k] * r[k];
}
q[j] = t;
}
}
del(c);
return m;
}
int main(int argc, char *argv[]) {
int n = 300;
n = (n/2) * 2;
var a = Matrix_Gen(n);
var b = Matrix_Gen(n);
var m = Matrix_Mul(a, b);
del(a); del(b); del(m);
return 0;
}
================================================
FILE: benchmarks/Matmul/matmul_cpp.cpp
================================================
#include <stdlib.h>
class Matrix {
public:
size_t n;
double** d;
Matrix(int n);
~Matrix();
};
Matrix::Matrix(int n) {
n = n;
d = (double**)malloc(n * sizeof(double*));
for (int i = 0; i < n; ++i) {
d[i] = (double*)calloc(n, sizeof(double));
}
}
Matrix::~Matrix() {
for (int i = 0; i < n; ++i) free(d[i]);
free(d);
}
static Matrix* Matrix_Gen(int n) {
Matrix* m = new Matrix(n);
double tmp = 1.0 / n / n;
for (int i = 0; i < m->n; ++i) {
for (int j = 0; j < m->n; ++j) {
m->d[i][j] = tmp * (i - j) * (i + j);
}
}
return m;
}
static Matrix* Matrix_Mul(Matrix* m0, Matrix* m1) {
Matrix* a = m0;
Matrix* b = m1;
Matrix* m = new Matrix(a->n);
Matrix* c = new Matrix(a->n);
for (int i = 0; i < m->n; ++i) {
for (int j = 0; j < m->n; ++j) {
c->d[i][j] = b->d[j][i];
}
}
for (int i = 0; i < m->n; ++i) {
double *p = a->d[i], *q = m->d[i];
for (int j = 0; j < m->n; ++j) {
double t = 0.0, *r = c->d[j];
for (int k = 0; k < m->n; ++k) {
t += p[k] * r[k];
}
q[j] = t;
}
}
delete c;
return m;
}
int main(int argc, char *argv[]) {
int n = 300;
n = (n/2) * 2;
Matrix* a = Matrix_Gen(n);
Matrix* b = Matrix_Gen(n);
Matrix* m = Matrix_Mul(a, b);
delete a; delete b; delete m;
return 0;
}
================================================
FILE: benchmarks/Matmul/matmul_cs.cs
================================================
// Written by Attractive Chaos; distributed under the MIT license
// To compile: mcs -optimize+ -out:matmul_v1.run matmul_v1.cs
// Translated from Java with reference to: http://code.wikia.com/wiki/Matrix_multiplication
using System;
class matmul_v1 {
public double[,] matgen(int n) {
double[,] a = new double[n,n];
double tmp = 1.0 / n / n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
a[i,j] = tmp * (i - j) * (i + j);
return a;
}
public double[,] matmul(double[,] a, double[,] b) {
int m = a.GetLength(0), n = a.GetLength(1), p = b.GetLength(0);
double[,] x = new double[m,p];
double[,] c = new double[p,n];
for (int i = 0; i < n; ++i) // transpose
for (int j = 0; j < p; ++j)
c[j,i] = b[i,j];
for (int i = 0; i < m; ++i)
for (int j = 0; j < p; ++j) {
double s = 0.0;
for (int k = 0; k < n; ++k)
s += a[i,k] * c[j,k];
x[i,j] = s;
}
return x;
}
public static void Main(String[] args) {
int n = 100;
if (args.GetLength(0) >= 1) n = int.Parse(args[0]);
n = n / 2 * 2;
matmul_v1 m = new matmul_v1();
double[,] a, b, x;
a = m.matgen(n);
b = m.matgen(n);
x = m.matmul(a, b);
Console.WriteLine(x[n/2,n/2]);
}
}
================================================
FILE: benchmarks/Matmul/matmul_d.d
================================================
// Originally written by Attractive Chaos; distributed under the MIT license (D V.2 code)
// Contributed by leonardo and then modified by Attractive Chaos to remove D 2.0 features
import std.stdio, std.string;
double[][] matGen(in int n) {
double tmp = 1.0 / n / n;
auto a = new double[][](n, n);
foreach (int i, row; a)
foreach (int j, ref x; row)
x = tmp * (i - j) * (i + j);
return a;
}
double[][] matMul(in double[][] a, in double[][] b) {
int m = a.length, n = a[0].length, p = b[0].length;
// transpose
auto c = new double[][](p, n);
foreach (i, brow; b)
foreach (j, bx; brow)
c[j][i] = bx;
auto x = new double[][](m, p);
foreach (i, arow; a)
foreach (j, crow; c) {
// x[i][j] = std.numeric.dotProduct(arow, crow); // right way
double s = 0.0;
foreach (k, arowk; arow)
s += arowk * crow[k];
x[i][j] = s;
}
return x;
}
void main(in string[] args) {
int n = 100;
if (args.length >= 2) n = atoi(args[1]) / 2 * 2;
auto a = matGen(n);
auto b = matGen(n);
auto x = matMul(a, b);
writefln(x[n / 2][n / 2]);
}
================================================
FILE: benchmarks/Matmul/matmul_dart.dart
================================================
import 'dart:scalarlist';
mat_transpose(a)
{
int m = a.length, n = a[0].length; // m rows and n cols
var b = new List(n);
for (int j = 0; j < n; ++j) b[j] = new Float64List(m);
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
b[j][i] = a[i][j];
return b;
}
mat_mul(a, b)
{
inner_loop(t, n, ai, c)
{
var xi = new Float64List(t);
for (int j = 0; j < t; ++j) {
double sum = 0.0;
for (int k = 0; k < n; ++k) sum += ai[k] * c[j][k];
xi[j] = sum;
}
return xi;
}
int m = a.length, n = a[0].length, s = b.length, t = b[0].length;
if (n != s) return null;
var x = new List(m), c = mat_transpose(b);
for (int i = 0; i < m; ++i)
x[i] = inner_loop(t, n, a[i], c);
return x;
}
mat_gen(int n)
{
var a = new List(n);
double t = 1.0 / n / n;
for (int i = 0; i < n; ++i) {
a[i] = new Float64List(n);
for (int j = 0; j < n; ++j)
a[i][j] = t * (i - j) * (i + j);
}
return a;
}
main()
{
List<String> argv = new Options().arguments;
int n = argv.length != 0? int.parse(argv[0]) : 1000;
var a = mat_gen(n), b = mat_gen(n);
var c = mat_mul(a, b);
print(c[n~/2][n~/2]);
}
================================================
FILE: benchmarks/Matmul/matmul_go.go
================================================
// Written by Attractive Chaos; distributed under the MIT license
package main
import "fmt"
import "flag"
import "strconv"
func matgen(n int) [][]float64 {
a := make([][]float64, n)
tmp := float64(1.0) / float64(n) / float64(n) // pretty silly...
for i := 0; i < n; i++ {
a[i] = make([]float64, n)
for j := 0; j < n; j++ {
a[i][j] = tmp * float64(i-j) * float64(i+j)
}
}
return a
}
func matmul(a [][]float64, b [][]float64) [][]float64 {
m := len(a)
n := len(a[0])
p := len(b[0])
x := make([][]float64, m)
c := make([][]float64, p)
for i := 0; i < p; i++ {
c[i] = make([]float64, n)
for j := 0; j < n; j++ {
c[i][j] = b[j][i]
}
}
for i, am := range a {
x[i] = make([]float64, p)
for j, cm := range c {
s := float64(0)
for k, m := range am {
s += m*cm[k]
}
x[i][j] = s
}
}
return x
}
func main() {
n := int(100)
flag.Parse()
if flag.NArg() > 0 { n,_ = strconv.Atoi(flag.Arg(0)) }
a := matgen(n)
b := matgen(n)
x := matmul(a, b)
fmt.Printf("%f\n", x[n/2][n/2])
}
================================================
FILE: benchmarks/Matmul/matmul_java.java
================================================
// Written by Attractive Chaos; distributed under the MIT license
class matmul_java {
public double[][] matgen(int n) {
double[][] a = new double[n][n];
double tmp = 1. / n / n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
a[i][j] = tmp * (i - j) * (i + j);
return a;
}
public double[][] matmul(double[][] a, double[][] b) {
int m = a.length, n = a[0].length, p = b[0].length;
double[][] x = new double[m][p];
double[][] c = new double[p][n];
for (int i = 0; i < n; ++i) // transpose
for (int j = 0; j < p; ++j)
c[j][i] = b[i][j];
for (int i = 0; i < m; ++i)
for (int j = 0; j < p; ++j) {
double s = 0.0;
for (int k = 0; k < n; ++k)
s += a[i][k] * c[j][k];
x[i][j] = s;
}
return x;
}
public static void main(String[] args) {
int n = 300;
n = n / 2 * 2;
matmul_java m = new matmul_java();
double[][] a, b, x;
a = m.matgen(n);
b = m.matgen(n);
x = m.matmul(a, b);
//System.out.println(x[n/2][n/2]);
}
}
================================================
FILE: benchmarks/Matmul/matmul_javascript.js
================================================
// Writen by Attractive Chaos; distributed under the MIT license
Math.m = {};
Math.m.T = function(a) { // matrix transpose
var b = [], m = a.length, n = a[0].length; // m rows and n cols
for (var j = 0; j < n; ++j) b[j] = [];
for (var i = 0; i < m; ++i)
for (var j = 0; j < n; ++j)
b[j].push(a[i][j]);
return b;
}
Math.m.mul = function(a, b) { // matrix mul
var m = a.length, n = a[0].length, s = b.length, t = b[0].length;
if (n != s) return null;
var x = [], c = Math.m.T(b);
for (var i = 0; i < m; ++i) {
x[i] = [];
for (var j = 0; j < t; ++j) {
var sum = 0;
var ai = a[i], cj = c[j];
for (var k = 0; k < n; ++k) sum += ai[k] * cj[k];
x[i].push(sum);
}
}
return x;
}
function matgen(n) {
var a = [], tmp = 1. / n / n;
for (i = 0; i < n; ++i) {
a[i] = []
for (j = 0; j < n; ++j)
a[i][j] = tmp * (i - j) * (i + j);
}
return a;
}
var n = 300;
var a = matgen(n);
var b = matgen(n);
var c = Math.m.mul(a, b);
//print(c[n/2][n/2]);
================================================
FILE: benchmarks/Matmul/matmul_lua.lua
================================================
-- Writen by Attractive Chaos; distributed under the MIT license
matrix = {}
function matrix.T(a)
local m, n, x = #a, #a[1], {};
for i = 1, n do
x[i] = {};
for j = 1, m do x[i][j] = a[j][i] end
end
return x;
end
function matrix.mul(a, b)
assert(#a[1] == #b);
local m, n, p, x = #a, #a[1], #b[1], {};
local c = matrix.T(b); -- transpose for efficiency
for i = 1, m do
x[i] = {}
local xi = x[i];
for j = 1, p do
local sum, ai, cj = 0, a[i], c[j];
-- for luajit, caching c[j] or not makes no difference; lua is not so clever
for k = 1, n do sum = sum + ai[k] * cj[k] end
xi[j] = sum;
end
end
return x;
end
function matgen(n)
local a, tmp = {}, 1. / n / n;
for i = 1, n do
a[i] = {}
for j = 1, n do
a[i][j] = tmp * (i - j) * (i + j - 2)
end
end
return a;
end
local n = 300;
n = math.floor(n/2) * 2;
local a = matrix.mul(matgen(n), matgen(n));
--print(a[n/2+1][n/2+1]);
================================================
FILE: benchmarks/Matmul/matmul_perl.pl
================================================
#!/usr/bin/perl -w
# Writen by Attractive Chaos; distributed under the MIT license
use strict;
use warnings;
&main;
sub main {
my $n = $ARGV[0] || 100;
$n = int($n/2) * 2;
my (@a, @b, @x);
&matgen($n, \@a); &matgen($n, \@b);
&mul(\@a, \@b, \@x);
print $x[$n/2][$n/2], "\n";
}
sub transpose {
my ($a, $b) = @_;
my $m = @$a;
my $n = @{$a->[0]};
@$b = ();
for my $i (0 .. $n - 1) {
@{$b->[$i]} = ();
for my $j (0 .. $m - 1) {
push(@{$b->[$i]}, $a->[$j][$i]);
}
}
}
sub mul {
my ($a, $b, $x) = @_;
my $m = @$a;
my $n = @{$a->[0]};
my $p = @{$b->[0]};
my @c;
&transpose($b, \@c);
for my $i (0 .. $m - 1) {
@{$x->[$i]} = ();
for my $j (0 .. $p - 1) {
my $sum = 0;
my ($ai, $cj) = ($a->[$i], $c[$j]);
for my $k (0 .. $n - 1) {
$sum += $ai->[$k] * $cj->[$k];
}
push(@{$x->[$i]}, $sum);
}
}
}
sub matgen {
my ($n, $a) = @_;
@$a = ();
my $tmp = 1. / $n / $n;
for my $i (0 .. $n - 1) {
for my $j (0 .. $n - 1) {
$a->[$i][$j] = $tmp * ($i - $j) * ($i + $j);
}
}
}
================================================
FILE: benchmarks/Matmul/matmul_python.py
================================================
import sys
# Writen by Attractive Chaos; distributed under the MIT license
# reference: http://www.syntagmatic.net/matrix-multiplication-in-python/
def matmul(a, b): # FIXME: no error checking
c = [[b[j][i] for j in range(len(b))] for i in range(len(b[0]))]
d = [[0 for j in range(len(b[0]))] for i in range(len(a))] # transpose
for i in range(len(a)):
for j in range(len(b[0])):
s = 0
ai = a[i]
cj = c[j]
for k in range(len(a[0])):
s += ai[k] * cj[k]
d[i][j] = s
return d
def main():
n = 300
n = int(float(n)/2) * 2 # FIXME: I am sure there are better ways to do this...
tmp = 1. / n / n
a = [[tmp * (i - j) * (i + j) for j in range(n)] for i in range(n)]
b = [[tmp * (i - j) * (i + j) for j in range(n)] for i in range(n)]
d = matmul(a, b)
#print(d[int(n/2)][int(n/2)])
if __name__ == '__main__': main()
================================================
FILE: benchmarks/Matmul/matmul_r.R
================================================
matgen <- function(n) {
y0 <- matrix(rep(seq(0, n-1), n), n)
y1 <- t(y0)
z <- 1 / n / n
(y0 - y1) * (y0 + y1) * z
}
matmul <- function(a, b) {
# transposing or not seems to make no difference
m <- dim(a)[1]
n <- dim(a)[2]
p <- dim(b)[2]
x <- matrix(rep(0, m * p), m)
for (i in seq(1, m)) {
for (j in seq(1, p)) {
#x[i,j] <- sum(a[i,], b[,j]) # using this line: 43.3 sec, 64.6 MB
s <- 0; ai <- a[i,]; bj <- b[,j]; for (k in seq(1, n)) s <- s + ai[k] * bj[k]; x[i,j] <- s
}
}
x
}
n <- as.integer(commandArgs(trailingOnly = T)[1])
if (is.na(n)) n <- 100
# x <- matgen(n) %*% matgen(n) # using this line: 2.7 sec, 53.0 MB
x <- matmul(matgen(n), matgen(n))
x[n/2+1,n/2+1]
================================================
FILE: benchmarks/Matmul/matmul_ruby.rb
================================================
# Writen by Attractive Chaos; distributed under the MIT license
# This version does not use the built-in Matrix object
# reference: http://vikhyat.net/articles/matrix_multiplication_ruby/
def matmul(a, b)
m = a.length
n = a[0].length
p = b[0].length
# transpose
b2 = Array.new(n) { Array.new(p) { 0 } }
for i in 0 .. n-1
for j in 0 .. p-1
b2[j][i] = b[i][j]
end
end
# multiplication
c = Array.new(m) { Array.new(p) { 0 } }
for i in 0 .. m-1
for j in 0 .. p-1
s = 0
ai, b2j = a[i], b2[j]
for k in 0 .. n-1
s += ai[k] * b2j[k]
end
c[i][j] = s
end
end
return c
end
def matgen(n)
tmp = 1.0 / n / n
a = Array.new(n) { Array.new(n) { 0 } }
for i in 0 .. n-1
for j in 0 .. n-1
a[i][j] = tmp * (i - j) * (i + j)
end
end
return a
end
n = 300
n = n / 2 * 2
a = matgen(n)
b = matgen(n)
c = matmul(a, b)
#puts c[n/2][n/2]
================================================
FILE: benchmarks/Nbodies/nbodies_c.c
================================================
#include <math.h>
#include <stdlib.h>
#undef M_PI
#define M_PI 3.14159265359
static const double solar_mass = 4 * M_PI * M_PI;
static const double days_per_year = 365.24;
struct Body {
double x, y, z;
double vx, vy, vz;
double mass;
};
static void Body_Offset_Momentum(struct Body* b, double px, double py, double pz) {
b->vx = -px / solar_mass;
b->vy = -py / solar_mass;
b->vz = -pz / solar_mass;
}
static void Bodies_Advance(struct Body* bodies, size_t nbodies, double dt) {
for(size_t i = 0; i < nbodies; i++) {
struct Body* body0 = &bodies[i];
for(size_t j = i+1; j < nbodies; j++) {
struct Body* body1 = &bodies[j];
double dx = body0->x - body1->x;
double dy = body0->y - body1->y;
double dz = body0->z - body1->z;
double dsquared = dx * dx + dy * dy + dz * dz;
double distance = sqrt(dsquared);
double mag = dt / (dsquared * distance);
body0->vx -= dx * body1->mass * mag;
body0->vy -= dy * body1->mass * mag;
body0->vz -= dz * body1->mass * mag;
body1->vx += dx * body0->mass * mag;
body1->vy += dy * body0->mass * mag;
body1->vz += dz * body0->mass * mag;
}
}
for(size_t i = 0; i < nbodies; i++) {
struct Body* b = &bodies[i];
b->x += dt * b->vx;
b->y += dt * b->vy;
b->z += dt * b->vz;
}
}
static double Bodies_Energy(struct Body* bodies, size_t nbodies) {
double dx = 0.0;
double dy = 0.0;
double dz = 0.0;
double distance = 0.0;
double e = 0.0;
for(size_t i = 0; i < nbodies; i++) {
struct Body* body0 = &bodies[i];
e += (0.5 * body0->mass * (
body0->vx * body0->vx +
body0->vy * body0->vy +
body0->vz * body0->vz));
for(size_t j = i+1; j < nbodies; j++) {
struct Body* body1 = &bodies[j];
dx = body0->x - body1->x;
dy = body0->y - body1->y;
dz = body0->z - body1->z;
distance = sqrt(dx * dx + dy * dy + dz * dz);
e -= (body0->mass * body1->mass) / distance;
}
}
return e;
}
int main(int argc, char** argv) {
struct Body jupiter = (struct Body){
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-00,
days_per_year * 1.66007664274403694e-03,
days_per_year * 7.69901118419740425e-03,
days_per_year * -6.90460016972063023e-05,
solar_mass * 9.54791938424326609e-04};
struct Body saturn = (struct Body){
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
days_per_year * -2.76742510726862411e-03,
days_per_year * 4.99852801234917238e-03,
days_per_year * 2.30417297573763929e-05,
solar_mass * 2.85885980666130812e-04};
struct Body uranus = (struct Body){
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
days_per_year * 2.96460137564761618e-03,
days_per_year * 2.37847173959480950e-03,
days_per_year * -2.96589568540237556e-05,
solar_mass * 4.36624404335156298e-05};
struct Body neptune = (struct Body){
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
days_per_year * 2.68067772490389322e-03,
days_per_year * 1.62824170038242295e-03,
days_per_year * -9.51592254519715870e-05,
solar_mass * 5.15138902046611451e-05};
struct Body sun = (struct Body){
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
solar_mass};
size_t nbodies = 5;
struct Body* bodies = (struct Body[5]){
jupiter, saturn, uranus, neptune, sun};
double px = 0.0;
double py = 0.0;
double pz = 0.0;
for(size_t i = 0; i < nbodies; i++) {
struct Body* b = &bodies[i];
px += b->vx * b->mass;
py += b->vy * b->mass;
pz += b->vz * b->mass;
}
Body_Offset_Momentum(&bodies[0], px, py, pz);
for(size_t i = 0; i < 100000; i++) {
Bodies_Advance(bodies, nbodies, 1e-5);
}
}
================================================
FILE: benchmarks/Nbodies/nbodies_cello.c
================================================
#include "Cello.h"
static const double solar_mass = 4 * M_PI * M_PI;
static const double days_per_year = 365.24;
struct Body {
double x, y, z;
double vx, vy, vz;
double mass;
};
static void Body_Offset_Momentum(struct Body* self, double px, double py, double pz) {
self->vx = -px / solar_mass;
self->vy = -py / solar_mass;
self->vz = -pz / solar_mass;
}
var Body = Cello(Body);
static void Bodies_Advance(var bodies, double dt) {
size_t nbodies = len(bodies);
foreach(i in range($I(nbodies))) {
struct Body* body0 = get(bodies, i);
foreach(j in range($I(c_int(i)+1), $I(nbodies))) {
struct Body* body1 = get(bodies, j);
double dx = body0->x - body1->x;
double dy = body0->y - body1->y;
double dz = body0->z - body1->z;
double dsquared = dx * dx + dy * dy + dz * dz;
double mag = dt / (dsquared * sqrt(dsquared));
body0->vx -= dx * body1->mass * mag;
body0->vy -= dy * body1->mass * mag;
body0->vz -= dz * body1->mass * mag;
body1->vx += dx * body0->mass * mag;
body1->vy += dy * body0->mass * mag;
body1->vz += dz * body0->mass * mag;
}
}
foreach (body in bodies) {
struct Body* b = body;
b->x += dt * b->vx;
b->y += dt * b->vy;
b->z += dt * b->vz;
}
}
static double Bodies_Energy(var bodies) {
double dx = 0.0;
double dy = 0.0;
double dz = 0.0;
double distance = 0.0;
double e = 0.0;
size_t nbodies = len(bodies);
foreach(i in range($I(nbodies))) {
struct Body* body0 = get(bodies, i);
e += (0.5 * body0->mass * (
body0->vx * body0->vx +
body0->vy * body0->vy +
body0->vz * body0->vz));
foreach(j in range($I(c_int(i)+1), $I(nbodies))) {
struct Body* body1 = get(bodies, j);
dx = body0->x - body1->x;
dy = body0->y - body1->y;
dz = body0->z - body1->z;
distance = sqrt(dx * dx + dy * dy + dz * dz);
e -= (body0->mass * body1->mass) / distance;
}
}
return e;
}
int main(int argc, char** argv) {
var jupiter = $(Body,
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-00,
days_per_year * 1.66007664274403694e-03,
days_per_year * 7.69901118419740425e-03,
days_per_year * -6.90460016972063023e-05,
solar_mass * 9.54791938424326609e-04);
var saturn = $(Body,
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
days_per_year * -2.76742510726862411e-03,
days_per_year * 4.99852801234917238e-03,
days_per_year * 2.30417297573763929e-05,
solar_mass * 2.85885980666130812e-04);
var uranus = $(Body,
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
days_per_year * 2.96460137564761618e-03,
days_per_year * 2.37847173959480950e-03,
days_per_year * -2.96589568540237556e-05,
solar_mass * 4.36624404335156298e-05);
var neptune = $(Body,
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
days_per_year * 2.68067772490389322e-03,
days_per_year * 1.62824170038242295e-03,
days_per_year * -9.51592254519715870e-05,
solar_mass * 5.15138902046611451e-05);
var sun = $(Body,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
solar_mass);
var bodies = new(Array, Body,
jupiter, saturn, uranus, neptune, sun);
double px = 0.0;
double py = 0.0;
double pz = 0.0;
foreach(body in bodies) {
struct Body* b = body;
px += b->vx * b->mass;
py += b->vy * b->mass;
pz += b->vz * b->mass;
}
Body_Offset_Momentum(get(bodies, $I(0)), px, py, pz);
foreach(i in range($I(100000))) {
Bodies_Advance(bodies, 1e-5);
}
del(bodies);
return 0;
}
================================================
FILE: benchmarks/Nbodies/nbodies_cpp.cpp
================================================
#include <vector>
#include <cmath>
#undef M_PI
#define M_PI 3.14159265358979323846
static const double solar_mass = 4 * M_PI * M_PI;
static const double days_per_year = 365.24;
class Body {
public:
Body(double x, double y, double z,
double vx, double vy, double vz, double mass)
: x(x), y(y), z(z), vx(vx), vy(vy), vz(vz), mass(mass) {}
double x, y, z;
double vx, vy, vz;
double mass;
void Offset_Momentum(double px, double py, double pz) {
vx = -px / solar_mass;
vy = -py / solar_mass;
vz = -pz / solar_mass;
}
};
static void Bodies_Advance(std::vector<Body*> bodies, double dt) {
for(int i = 0; i < bodies.size(); i++) {
Body* body0 = bodies[i];
for(int j = i+1; j < bodies.size(); j++) {
Body* body1 = bodies[j];
double dx = body0->x - body1->x;
double dy = body0->y - body1->y;
double dz = body0->z - body1->z;
double dsquared = dx * dx + dy * dy + dz * dz;
double distance = sqrt(dsquared);
double mag = dt / (dsquared * distance);
body0->vx -= dx * body1->mass * mag;
body0->vy -= dy * body1->mass * mag;
body0->vz -= dz * body1->mass * mag;
body1->vx += dx * body0->mass * mag;
body1->vy += dy * body0->mass * mag;
body1->vz += dz * body0->mass * mag;
}
}
for (auto &b : bodies) {
b->x += dt * b->vx;
b->y += dt * b->vy;
b->z += dt * b->vz;
}
}
static double Bodies_Energy(std::vector<Body*> bodies) {
double dx = 0.0;
double dy = 0.0;
double dz = 0.0;
double distance = 0.0;
double e = 0.0;
for(int i = 0; i < bodies.size(); i++) {
Body* body0 = bodies[i];
e += (0.5 * body0->mass * (
body0->vx * body0->vx +
body0->vy * body0->vy +
body0->vz * body0->vz));
for(int j = i+1; j < bodies.size(); j++) {
Body* body1 = bodies[j];
dx = body0->x - body1->x;
dy = body0->y - body1->y;
dz = body0->z - body1->z;
distance = sqrt(dx * dx + dy * dy + dz * dz);
e -= (body0->mass * body1->mass) / distance;
}
}
return e;
}
int main(int argc, char** argv) {
Body jupiter = Body(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-00,
days_per_year * 1.66007664274403694e-03,
days_per_year * 7.69901118419740425e-03,
days_per_year * -6.90460016972063023e-05,
solar_mass * 9.54791938424326609e-04);
Body saturn = Body(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
days_per_year * -2.76742510726862411e-03,
days_per_year * 4.99852801234917238e-03,
days_per_year * 2.30417297573763929e-05,
solar_mass * 2.85885980666130812e-04);
Body uranus = Body(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
days_per_year * 2.96460137564761618e-03,
days_per_year * 2.37847173959480950e-03,
days_per_year * -2.96589568540237556e-05,
solar_mass * 4.36624404335156298e-05);
Body neptune = Body(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
days_per_year * 2.68067772490389322e-03,
days_per_year * 1.62824170038242295e-03,
days_per_year * -9.51592254519715870e-05,
solar_mass * 5.15138902046611451e-05);
Body sun = Body(
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
solar_mass);
auto bodies = std::vector<Body*>();
bodies.push_back(&jupiter);
bodies.push_back(&saturn);
bodies.push_back(&uranus);
bodies.push_back(&neptune);
bodies.push_back(&sun);
double px = 0.0;
double py = 0.0;
double pz = 0.0;
for(auto &b : bodies) {
px += b->vx * b->mass;
py += b->vy * b->mass;
pz += b->vz * b->mass;
}
bodies[0]->Offset_Momentum(px, py, pz);
for(int i = 0; i < 100000; i++) {
Bodies_Advance(bodies, 1e-5);
}
}
================================================
FILE: benchmarks/Nbodies/nbodies_java.java
================================================
public final class nbodies_java {
public static void main(String[] args) {
NBodySystem bodies = new NBodySystem();
for (int i=0; i<100000; ++i) {
bodies.advance(1e-5);
}
}
}
final class NBodySystem {
private Body[] bodies;
public NBodySystem(){
bodies = new Body[]{
Body.sun(),
Body.jupiter(),
Body.saturn(),
Body.uranus(),
Body.neptune()
};
double px = 0.0;
double py = 0.0;
double pz = 0.0;
for(int i=0; i < bodies.length; ++i) {
px += bodies[i].vx * bodies[i].mass;
py += bodies[i].vy * bodies[i].mass;
pz += bodies[i].vz * bodies[i].mass;
}
bodies[0].offsetMomentum(px,py,pz);
}
public void advance(double dt) {
for(int i=0; i < bodies.length; ++i) {
Body iBody = bodies[i];
for(int j=i+1; j < bodies.length; ++j) {
double dx = iBody.x - bodies[j].x;
double dy = iBody.y - bodies[j].y;
double dz = iBody.z - bodies[j].z;
double dSquared = dx * dx + dy * dy + dz * dz;
double distance = Math.sqrt(dSquared);
double mag = dt / (dSquared * distance);
iBody.vx -= dx * bodies[j].mass * mag;
iBody.vy -= dy * bodies[j].mass * mag;
iBody.vz -= dz * bodies[j].mass * mag;
bodies[j].vx += dx * iBody.mass * mag;
bodies[j].vy += dy * iBody.mass * mag;
bodies[j].vz += dz * iBody.mass * mag;
}
}
for ( Body body : bodies) {
body.x += dt * body.vx;
body.y += dt * body.vy;
body.z += dt * body.vz;
}
}
public double energy(){
double dx, dy, dz, distance;
double e = 0.0;
for (int i=0; i < bodies.length; ++i) {
Body iBody = bodies[i];
e += 0.5 * iBody.mass *
( iBody.vx * iBody.vx
+ iBody.vy * iBody.vy
+ iBody.vz * iBody.vz );
for (int j=i+1; j < bodies.length; ++j) {
Body jBody = bodies[j];
dx = iBody.x - jBody.x;
dy = iBody.y - jBody.y;
dz = iBody.z - jBody.z;
distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
e -= (iBody.mass * jBody.mass) / distance;
}
}
return e;
}
}
final class Body {
static final double PI = 3.141592653589793;
static final double SOLAR_MASS = 4 * PI * PI;
static final double DAYS_PER_YEAR = 365.24;
public double x, y, z, vx, vy, vz, mass;
public Body(){}
static Body jupiter(){
Body p = new Body();
p.x = 4.84143144246472090e+00;
p.y = -1.16032004402742839e+00;
p.z = -1.03622044471123109e-01;
p.vx = 1.66007664274403694e-03 * DAYS_PER_YEAR;
p.vy = 7.69901118419740425e-03 * DAYS_PER_YEAR;
p.vz = -6.90460016972063023e-05 * DAYS_PER_YEAR;
p.mass = 9.54791938424326609e-04 * SOLAR_MASS;
return p;
}
static Body saturn(){
Body p = new Body();
p.x = 8.34336671824457987e+00;
p.y = 4.12479856412430479e+00;
p.z = -4.03523417114321381e-01;
p.vx = -2.76742510726862411e-03 * DAYS_PER_YEAR;
p.vy = 4.99852801234917238e-03 * DAYS_PER_YEAR;
p.vz = 2.30417297573763929e-05 * DAYS_PER_YEAR;
p.mass = 2.85885980666130812e-04 * SOLAR_MASS;
return p;
}
static Body uranus(){
Body p = new Body();
p.x = 1.28943695621391310e+01;
p.y = -1.51111514016986312e+01;
p.z = -2.23307578892655734e-01;
p.vx = 2.96460137564761618e-03 * DAYS_PER_YEAR;
p.vy = 2.37847173959480950e-03 * DAYS_PER_YEAR;
p.vz = -2.96589568540237556e-05 * DAYS_PER_YEAR;
p.mass = 4.36624404335156298e-05 * SOLAR_MASS;
return p;
}
static Body neptune(){
Body p = new Body();
p.x = 1.53796971148509165e+01;
p.y = -2.59193146099879641e+01;
p.z = 1.79258772950371181e-01;
p.vx = 2.68067772490389322e-03 * DAYS_PER_YEAR;
p.vy = 1.62824170038242295e-03 * DAYS_PER_YEAR;
p.vz = -9.51592254519715870e-05 * DAYS_PER_YEAR;
p.mass = 5.15138902046611451e-05 * SOLAR_MASS;
return p;
}
static Body sun(){
Body p = new Body();
p.mass = SOLAR_MASS;
return p;
}
Body offsetMomentum(double px, double py, double pz){
vx = -px / SOLAR_MASS;
vy = -py / SOLAR_MASS;
vz = -pz / SOLAR_MASS;
return this;
}
}
================================================
FILE: benchmarks/Nbodies/nbodies_javascript.js
================================================
var pi = 3.141592653589793
var solar_mass = 4 * pi * pi
var days_per_year = 365.24
var jupiter = {
x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01,
vx: days_per_year * 1.66007664274403694e-03,
vy: days_per_year * 7.69901118419740425e-03,
vz: days_per_year * -6.90460016972063023e-05,
mass: solar_mass * 9.54791938424326609e-04}
var saturn = {
x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01,
vx: days_per_year * -2.76742510726862411e-03,
vy: days_per_year * 4.99852801234917238e-03,
vz: days_per_year * 2.30417297573763929e-05,
mass: solar_mass * 2.85885980666130812e-04}
var uranus = {
x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01,
vx: days_per_year * 2.96460137564761618e-03,
vy: days_per_year * 2.37847173959480950e-03,
vz: days_per_year * -2.96589568540237556e-05,
mass: solar_mass * 4.36624404335156298e-05}
var neptune = {
x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01,
vx: days_per_year * 2.68067772490389322e-03,
vy: days_per_year * 1.62824170038242295e-03,
vz: days_per_year * -9.51592254519715870e-05,
mass: solar_mass * 5.15138902046611451e-05}
var sun = {
x: 0.0, y: 0.0, z: 0.0,
vx: 0.0, vy: 0.0, vz: 0.0,
mass: solar_mass}
function body_offset_momentum(b, px, py, pz) {
b.vx = -px / solar_mass
b.vy = -py / solar_mass
b.vz = -pz / solar_mass
}
function bodies_new() {
bodies = [jupiter, saturn, uranus, neptune, sun];
px = 0.0;
py = 0.0;
pz = 0.0;
for (var i = 0; i < bodies.length; i++) {
body = bodies[i];
px += body.vx * body.mass;
py += body.vy * body.mass;
pz += body.vz * body.mass;
}
body_offset_momentum(bodies[0], px, py, pz);
return bodies;
}
function bodies_advance(bodies, dt) {
for (var i = 0; i < bodies.length; i++) {
var body0 = bodies[i]
for (var j = i+1; j < bodies.length; j++) {
var body1 = bodies[j];
var dx = body0.x - body1.x;
var dy = body0.y - body1.y;
var dz = body0.z - body1.z;
var dsquared = dx * dx + dy * dy + dz * dz;
var distance = Math.sqrt(dsquared);
var mag = dt / (dsquared * distance);
body0.vx -= dx * body1.mass * mag;
body0.vy -= dy * body1.mass * mag;
body0.vz -= dz * body1.mass * mag;
body1.vx += dx * body0.mass * mag;
body1.vy += dy * body0.mass * mag;
body1.vz += dz * body0.mass * mag;
}
}
for (var i = 0; i < bodies.length; i++) {
body = bodies[i];
body.x += dt * body.vx;
body.y += dt * body.vy;
body.z += dt * body.vz;
}
}
function bodies_energy(bodies) {
var dx = 0.0;
var dy = 0.0;
var dz = 0.0;
var distance = 0.0;
var e = 0.0;
for (var i = 0; i < bodies.length; i++) {
var body0 = bodies[i];
e += (0.5 * body0.mass * (
body0.vx * body0.vx +
body0.vy * body0.vy +
body0.vz * body0.vz));
for (var j = i+1; j < bodies.length; j++) {
var body1 = bodies[j];
dx = body0.x - body1.x;
dy = body0.y - body1.y;
dz = body0.z - body1.z;
distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
e -= (body0.mass * body1.mass) / distance;
}
}
return e;
}
var bodies = bodies_new()
for (var i = 0; i < 100000; i++) {
bodies_advance(bodies, 1e-5)
}
================================================
FILE: benchmarks/Nbodies/nbodies_lua.lua
================================================
local pi = 3.141592653589793
local solar_mass = 4 * pi * pi
local days_per_year = 365.24
local jupiter = {
x=4.84143144246472090e+00,
y=-1.16032004402742839e+00,
z=-1.03622044471123109e-01,
vx=days_per_year * 1.66007664274403694e-03,
vy=days_per_year * 7.69901118419740425e-03,
vz=days_per_year * -6.90460016972063023e-05,
mass=solar_mass * 9.54791938424326609e-04}
local saturn = {
x=8.34336671824457987e+00,
y=4.12479856412430479e+00,
z=-4.03523417114321381e-01,
vx=days_per_year * -2.76742510726862411e-03,
vy=days_per_year * 4.99852801234917238e-03,
vz=days_per_year * 2.30417297573763929e-05,
mass=solar_mass * 2.85885980666130812e-04}
local uranus = {
x=1.28943695621391310e+01,
y=-1.51111514016986312e+01,
z=-2.23307578892655734e-01,
vx=days_per_year * 2.96460137564761618e-03,
vy=days_per_year * 2.37847173959480950e-03,
vz=days_per_year * -2.96589568540237556e-05,
mass=solar_mass * 4.36624404335156298e-05}
local neptune = {
x=1.53796971148509165e+01,
y=-2.59193146099879641e+01,
z=1.79258772950371181e-01,
vx=days_per_year * 2.68067772490389322e-03,
vy=days_per_year * 1.62824170038242295e-03,
vz=days_per_year * -9.51592254519715870e-05,
mass=solar_mass * 5.15138902046611451e-05}
local sun = {
x=0.0, y=0.0, z=0.0,
vx=0.0, vy=0.0, vz=0.0,
mass=solar_mass}
function body_offset_momentum (b, px, py, pz)
b.vx = -px / solar_mass
b.vy = -py / solar_mass
b.vz = -pz / solar_mass
end
function bodies_advance(bodies, dt)
for i = 1, #bodies do
local body0 = bodies[i]
for j = i+1, #bodies do
local body1 = bodies[j];
local dx = body0.x - body1.x;
local dy = body0.y - body1.y;
local dz = body0.z - body1.z;
local dsquared = dx * dx + dy * dy + dz * dz;
local distance = math.sqrt(dsquared);
local mag = dt / (dsquared * distance);
body0.vx = body0.vx - dx * body1.mass * mag;
body0.vy = body0.vy -dy * body1.mass * mag;
body0.vz = body0.vz -dz * body1.mass * mag;
body1.vx = body1.vx + dx * body0.mass * mag;
body1.vy = body1.vy + dy * body0.mass * mag;
body1.vz = body1.vz + dz * body0.mass * mag;
end
end
for i = 1, #bodies do
body = bodies[i];
body.x = body.x + dt * body.vx;
body.y = body.y + dt * body.vy;
body.z = body.z + dt * body.vz;
end
end
function bodies_energy(bodies)
local dx = 0.0;
local dy = 0.0;
local dz = 0.0;
local distance = 0.0;
local e = 0.0;
for i = 1, #bodies.length do
local body0 = bodies[i];
e = e + (0.5 * body0.mass * (
body0.vx * body0.vx +
body0.vy * body0.vy +
body0.vz * body0.vz));
for j = i+1, #bodies do
local body1 = bodies[j];
dx = body0.x - body1.x;
dy = body0.y - body1.y;
dz = body0.z - body1.z;
distance = sqrt(dx * dx + dy * dy + dz * dz);
e = e - (body0.mass * body1.mass) / distance;
end
end
return e;
end
local bodies = {jupiter, saturn, uranus, neptune, sun};
local px = 0.0;
local py = 0.0;
local pz = 0.0;
for i = 1, #bodies do
local body = bodies[i];
px = px + body.vx * body.mass;
py = py + body.vy * body.mass;
pz = pz + body.vz * body.mass;
end
body_offset_momentum(bodies[1], px, py, pz);
for i = 1, 100000 do
bodies_advance(bodies, 1e-5)
end
================================================
FILE: benchmarks/Nbodies/nbodies_python.py
================================================
import math
import sys
# Constants
pi = 3.141592653589793
solar_mass = 4 * pi * pi
days_per_year = 365.24
# Bodies
class Body:
def __init__(self, x, y, z, vx, vy, vz, mass):
self.x = x
self.y = y
self.z = z
self.vx = vx
self.vy = vy
self.vz = vz
self.mass = mass
jupiter = Body(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
days_per_year * 1.66007664274403694e-03,
days_per_year * 7.69901118419740425e-03,
days_per_year * -6.90460016972063023e-05,
solar_mass * 9.54791938424326609e-04
)
saturn = Body(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
days_per_year * -2.76742510726862411e-03,
days_per_year * 4.99852801234917238e-03,
days_per_year * 2.30417297573763929e-05,
solar_mass * 2.85885980666130812e-04
)
uranus = Body(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
days_per_year * 2.96460137564761618e-03,
days_per_year * 2.37847173959480950e-03,
days_per_year * -2.96589568540237556e-05,
solar_mass * 4.36624404335156298e-05
)
neptune = Body(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
days_per_year * 2.68067772490389322e-03,
days_per_year * 1.62824170038242295e-03,
days_per_year * -9.51592254519715870e-05,
solar_mass * 5.15138902046611451e-05
)
sun = Body(
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
solar_mass
)
def body_offset_momentum(b, px, py, pz):
b.vx = -px / solar_mass
b.vy = -py / solar_mass
b.vz = -pz / solar_mass
def bodies_new():
bodies = [jupiter, saturn, uranus, neptune, sun]
px = 0.0
py = 0.0
pz = 0.0
for body in bodies:
px += body.vx * body.mass
py += body.vy * body.mass
pz += body.vz * body.mass
body_offset_momentum(bodies[0], px, py, pz)
return bodies
# Simulation
def bodies_advance(bodies, dt):
for i in xrange(len(bodies)):
body0 = bodies[i]
for j in xrange(i+1, len(bodies)):
body1 = bodies[j]
dx = body0.x - body1.x
dy = body0.y - body1.y
dz = body0.z - body1.z
dsquared = dx * dx + dy * dy + dz * dz
distance = math.sqrt(dsquared)
mag = dt / (dsquared * distance)
body0.vx -= dx * body1.mass * mag
body0.vy -= dy * body1.mass * mag
body0.vz -= dz * body1.mass * mag
body1.vx += dx * body0.mass * mag
body1.vy += dy * body0.mass * mag
body1.vz += dz * body0.mass * mag
for body in bodies:
body.x += dt * body.vx
body.y += dt * body.vy
body.z += dt * body.vz
def bodies_energy(bodies):
dx = 0.0
dy = 0.0
dz = 0.0
distance = 0.0
e = 0.0
for i in xrange(len(bodies)):
body0 = bodies[i]
e += (0.5 * body0.mass * (
body0.vx * body0.vx +
body0.vy * body0.vy +
body0.vz * body0.vz))
for j in xrange(i+1, len(bodies)):
body1 = bodies[j]
dx = body0.x - body1.x
dy = body0.y - body1.y
dz = body0.z - body1.z
distance = math.sqrt(dx * dx + dy * dy + dz * dz)
e -= (body0.mass * body1.mass) / distance
return e
# Run
bodies = bodies_new()
for i in xrange(100000):
bodies_advance(bodies, 1e-5)
================================================
FILE: benchmarks/Nbodies/nbodies_ruby.rb
================================================
SOLAR_MASS = 4 * Math::PI**2
DAYS_PER_YEAR = 365.24
class Planet
attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass
def initialize(x, y, z, vx, vy, vz, mass)
@x, @y, @z = x, y, z
@vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
@mass = mass * SOLAR_MASS
end
def move_from_i(bodies, nbodies, dt, i)
while i < nbodies
b2 = bodies[i]
dx = @x - b2.x
dy = @y - b2.y
dz = @z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
mag = dt / (distance * distance * distance)
b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag
@vx -= dx * b2_mass_mag
@vy -= dy * b2_mass_mag
@vz -= dz * b2_mass_mag
b2.vx += dx * b_mass_mag
b2.vy += dy * b_mass_mag
b2.vz += dz * b_mass_mag
i += 1
end
@x += dt * @vx
@y += dt * @vy
@z += dt * @vz
end
end
def energy(bodies)
e = 0.0
nbodies = bodies.size
for i in 0 ... nbodies
b = bodies[i]
e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
for j in (i + 1) ... nbodies
b2 = bodies[j]
dx = b.x - b2.x
dy = b.y - b2.y
dz = b.z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
e -= (b.mass * b2.mass) / distance
end
end
e
end
def offset_momentum(bodies)
px, py, pz = 0.0, 0.0, 0.0
for b in bodies
m = b.mass
px += b.vx * m
py += b.vy * m
pz += b.vz * m
end
b = bodies[0]
b.vx = - px / SOLAR_MASS
b.vy = - py / SOLAR_MASS
b.vz = - pz / SOLAR_MASS
end
BODIES = [
# sun
Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
# jupiter
Planet.new(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
1.66007664274403694e-03,
7.69901118419740425e-03,
-6.90460016972063023e-05,
9.54791938424326609e-04),
# saturn
Planet.new(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
-2.76742510726862411e-03,
4.99852801234917238e-03,
2.30417297573763929e-05,
2.85885980666130812e-04),
# uranus
Planet.new(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
2.96460137564761618e-03,
2.37847173959480950e-03,
-2.96589568540237556e-05,
4.36624404335156298e-05),
# neptune
Planet.new(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
2.68067772490389322e-03,
1.62824170038242295e-03,
-9.51592254519715870e-05,
5.15138902046611451e-05)
]
offset_momentum(BODIES)
100000.times do
i = 0
while i < BODIES.size
b = BODIES[i]
b.move_from_i(BODIES, BODIES.size, 1e-5, i + 1)
i += 1
end
end
================================================
FILE: benchmarks/Sudoku/sudoku_c.c
================================================
/* The MIT License
Copyright (c) 2011 by Attractive Chaos <attractor@live.co.uk>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file implements an improved algorithm of Guenter Stertenbrink's suexco.c
// (http://magictour.free.fr/suexco.txt).
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
/* For Sudoku, there are 9x9x9=729 possible choices (9 numbers to choose for
each cell in a 9x9 grid), and 4x9x9=324 constraints with each constraint
representing a set of choices that are mutually conflictive with each other.
The 324 constraints are classified into 4 categories:
1. row-column where each cell contains only one number
2. box-number where each number appears only once in one 3x3 box
3. row-number where each number appears only once in one row
4. col-number where each number appears only once in one column
Each category consists of 81 constraints. We number these constraints from 0
to 323. In this program, for example, constraint 0 requires that the (0,0)
cell contains only one number; constraint 81 requires that number 1 appears
only once in the upper-left 3x3 box; constraint 162 requires that number 1
appears only once in row 1; constraint 243 requires that number 1 appears
only once in column 1.
Noting that a constraint is a subset of choices, we may represent a
constraint with a binary vector of 729 elements. Thus we have a 729x324
binary matrix M with M(r,c)=1 indicating the constraint c involves choice r.
Solving a Sudoku is reduced to finding a subset of choices such that no
choices are present in the same constaint. This is equivalent to finding the
minimal subset of choices intersecting all constraints, a minimum hitting
set problem or a eqivalence of the exact cover problem.
The 729x324 binary matrix is a sparse matrix, with each row containing 4
non-zero elements and each column 9 non-zero elements. In practical
implementation, we store the coordinate of non-zero elements instead of
the binary matrix itself. We use a binary row vector to indicate the
constraints that have not been used and use a column vector to keep the
number of times a choice has been forbidden. When we set a choice, we will
use up 4 constraints and forbid other choices in the 4 constraints. When we
make wrong choices, we will find an unused constraint with all choices
forbidden, in which case, we have to backtrack to make new choices. Once we
understand what the 729x324 matrix represents, the backtracking algorithm
itself is easy.
A major difference between the algorithm implemented here and Guenter
Stertenbrink's suexco.c lies in how to count the number of the available
choices for each constraint. Suexco.c computes the count with a loop, while
the algorithm here keeps the count in an array. The latter is a little more
complex to implement as we have to keep the counts synchronized all the time,
but it is 50-100% faster, depending on the input.
*/
// the sparse representation of the binary matrix
typedef struct {
uint16_t r[324][9]; // M(r[c][i], c) is a non-zero element
uint16_t c[729][4]; // M(r, c[r][j]) is a non-zero element
} sdaux_t;
// generate the sparse representation of the binary matrix
sdaux_t *sd_genmat()
{
sdaux_t *a;
int i, j, k, r, c, c2, r2;
int8_t nr[324];
a = calloc(1, sizeof(sdaux_t));
for (i = r = 0; i < 9; ++i) // generate c[729][4]
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k) // this "9" means each cell has 9 possible numbers
a->c[r][0] = 9 * i + j, // row-column constraint
a->c[r][1] = (i/3*3 + j/3) * 9 + k + 81, // box-number constraint
a->c[r][2] = 9 * i + k + 162, // row-number constraint
a->c[r][3] = 9 * j + k + 243, // col-number constraint
++r;
for (c = 0; c < 324; ++c) nr[c] = 0;
for (r = 0; r < 729; ++r) // generate r[][] from c[][]
for (c2 = 0; c2 < 4; ++c2)
k = a->c[r][c2], a->r[k][nr[k]++] = r;
return a;
}
// update the state vectors when we pick up choice r; v=1 for setting choice; v=-1 for reverting
static inline int sd_update(const sdaux_t *aux, int8_t sr[729], uint8_t sc[324], int r, int v)
{
int c2, min = 10, min_c = 0;
for (c2 = 0; c2 < 4; ++c2) sc[aux->c[r][c2]] += v<<7;
for (c2 = 0; c2 < 4; ++c2) { // update # available choices
int r2, rr, cc2, c = aux->c[r][c2];
if (v > 0) { // move forward
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = aux->r[c][r2]]++ != 0) continue; // update the row status
for (cc2 = 0; cc2 < 4; ++cc2) {
int cc = aux->c[rr][cc2];
if (--sc[cc] < min) // update # allowed choices
min = sc[cc], min_c = cc; // register the minimum number
}
}
} else { // revert
const uint16_t *p;
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = aux->r[c][r2]] != 0) continue; // update the row status
p = aux->c[rr]; ++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]]; // update the count array
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
// solve a Sudoku; _s is the standard dot/number representation
int sd_solve(const sdaux_t *aux, const char *_s)
{
int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack
int8_t sr[729], cr[81]; // sr[r]: # times the row is forbidden by others; cr[i]: row chosen at step i
uint8_t sc[324]; // bit 1-7: # allowed choices; bit 8: the constraint has been used or not
int16_t cc[81]; // cc[i]: col chosen at step i
char out[82];
for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden
for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used
for (i = 0; i < 81; ++i) {
int a = _s[i] >= '1' && _s[i] <= '9'? _s[i] - '1' : -1; // number from -1 to 8
if (a >= 0) sd_update(aux, sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0) ++hints; // count the number of hints
cr[i] = cc[i] = -1, out[i] = _s[i];
}
for (i = 0, dir = 1, cand = 10<<16|0, out[81] = 0;;) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand>>16, cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c], cc[i] = c; // choose the top constraint
if (min <= 1) break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) sd_update(aux, sr, sc, aux->r[c][cr[i]], -1); // revert the choice
for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make
if (sr[aux->r[c][r2]] == 0) break; // found if the state equals 0
if (r2 < 9) {
cand = sd_update(aux, sr, sc, aux->r[c][r2], 1); // set the choice
cr[i++] = r2; dir = 1; // moving forward
} else cr[i--] = dir = -1; // backtrack
}
if (i < 0) break;
for (j = 0; j < i; ++j) r = aux->r[cc[j]][cr[j]], out[r/9] = r%9 + '1'; // print
//puts(out);
++n; --i; dir = -1; // backtrack
}
return n; // return the number of solutions
}
int main()
{
sdaux_t *a = sd_genmat();
char buf[1024];
while (fgets(buf, 1024, stdin) != 0) {
if (strlen(buf) < 81) continue;
sd_solve(a, buf);
//putchar('\n');
}
free(a);
return 0;
}
================================================
FILE: benchmarks/Sudoku/sudoku_cello.c
================================================
#include "Cello.h"
struct Sudoku {
uint16_t r[324][9];
uint16_t c[729][4];
};
static void Sudoku_New(var self, var args) {
struct Sudoku* a = self;
int i, j, k, r, c, c2;
int8_t nr[324];
for (i = r = 0; i < 9; ++i) // generate c[729][4]
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k) // this "9" means each cell has 9 possible numbers
a->c[r][0] = 9 * i + j, // row-column constraint
a->c[r][1] = (i/3*3 + j/3) * 9 + k + 81, // box-number constraint
a->c[r][2] = 9 * i + k + 162, // row-number constraint
a->c[r][3] = 9 * j + k + 243, // col-number constraint
++r;
for (c = 0; c < 324; ++c) nr[c] = 0;
for (r = 0; r < 729; ++r) // generate r[][] from c[][]
for (c2 = 0; c2 < 4; ++c2)
k = a->c[r][c2], a->r[k][nr[k]++] = r;
}
static var Sudoku = Cello(Sudoku, Instance(New, Sudoku_New, NULL));
static int Sudoku_Update(
struct Sudoku* aux, int8_t sr[729], uint8_t sc[324], int r, int v) {
int c2, min = 10, min_c = 0;
for (c2 = 0; c2 < 4; ++c2) sc[aux->c[r][c2]] += v<<7;
for (c2 = 0; c2 < 4; ++c2) { // update # available choices
int r2, rr, cc2, c = aux->c[r][c2];
if (v > 0) { // move forward
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = aux->r[c][r2]]++ != 0) continue; // update the row status
for (cc2 = 0; cc2 < 4; ++cc2) {
int cc = aux->c[rr][cc2];
if (--sc[cc] < min) // update # allowed choices
min = sc[cc], min_c = cc; // register the minimum number
}
}
} else { // revert
const uint16_t *p;
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = aux->r[c][r2]] != 0) continue; // update the row status
p = aux->c[rr]; ++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]]; // update the count array
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
// solve a Sudoku; _s is the standard dot/number representation
static int Sudoku_Solve(struct Sudoku* aux, const char *_s) {
int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack
int8_t sr[729], cr[81]; // sr[r]: # times the row is forbidden by others; cr[i]: row chosen at step i
uint8_t sc[324]; // bit 1-7: # allowed choices; bit 8: the constraint has been used or not
int16_t cc[81]; // cc[i]: col chosen at step i
char out[82];
for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden
for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used
for (i = 0; i < 81; ++i) {
int a = _s[i] >= '1' && _s[i] <= '9'? _s[i] - '1' : -1; // number from -1 to 8
if (a >= 0) Sudoku_Update(aux, sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0) ++hints; // count the number of hints
cr[i] = cc[i] = -1, out[i] = _s[i];
}
for (i = 0, dir = 1, cand = 10<<16|0, out[81] = 0;;) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand>>16, cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c], cc[i] = c; // choose the top constraint
if (min <= 1) break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) Sudoku_Update(aux, sr, sc, aux->r[c][cr[i]], -1); // revert the choice
for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make
if (sr[aux->r[c][r2]] == 0) break; // found if the state equals 0
if (r2 < 9) {
cand = Sudoku_Update(aux, sr, sc, aux->r[c][r2], 1); // set the choice
cr[i++] = r2; dir = 1; // moving forward
} else cr[i--] = dir = -1; // backtrack
}
if (i < 0) break;
for (j = 0; j < i; ++j) r = aux->r[cc[j]][cr[j]], out[r/9] = r%9 + '1'; // print
//puts(out);
++n; --i; dir = -1; // backtrack
}
return n; // return the number of solutions
}
int main(int argc, char** argv) {
struct Sudoku* a = new(Sudoku);
char buf[1024];
while (fgets(buf, 1024, stdin) != 0) {
if (strlen(buf) < 81) continue;
Sudoku_Solve(a, buf);
//putchar('\n');
}
del(a);
return 0;
}
================================================
FILE: benchmarks/Sudoku/sudoku_cpp.cpp
================================================
/* The MIT License
Copyright (c) 2011 by Attractive Chaos <attractor@live.co.uk>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file implements an improved algorithm of Guenter Stertenbrink's suexco.c
// (http://magictour.free.fr/suexco.txt).
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
/* For Sudoku, there are 9x9x9=729 possible choices (9 numbers to choose for
each cell in a 9x9 grid), and 4x9x9=324 constraints with each constraint
representing a set of choices that are mutually conflictive with each other.
The 324 constraints are classified into 4 categories:
1. row-column where each cell contains only one number
2. box-number where each number appears only once in one 3x3 box
3. row-number where each number appears only once in one row
4. col-number where each number appears only once in one column
Each category consists of 81 constraints. We number these constraints from 0
to 323. In this program, for example, constraint 0 requires that the (0,0)
cell contains only one number; constraint 81 requires that number 1 appears
only once in the upper-left 3x3 box; constraint 162 requires that number 1
appears only once in row 1; constraint 243 requires that number 1 appears
only once in column 1.
Noting that a constraint is a subset of choices, we may represent a
constraint with a binary vector of 729 elements. Thus we have a 729x324
binary matrix M with M(r,c)=1 indicating the constraint c involves choice r.
Solving a Sudoku is reduced to finding a subset of choices such that no
choices are present in the same constaint. This is equivalent to finding the
minimal subset of choices intersecting all constraints, a minimum hitting
set problem or a eqivalence of the exact cover problem.
The 729x324 binary matrix is a sparse matrix, with each row containing 4
non-zero elements and each column 9 non-zero elements. In practical
implementation, we store the coordinate of non-zero elements instead of
the binary matrix itself. We use a binary row vector to indicate the
constraints that have not been used and use a column vector to keep the
number of times a choice has been forbidden. When we set a choice, we will
use up 4 constraints and forbid other choices in the 4 constraints. When we
make wrong choices, we will find an unused constraint with all choices
forbidden, in which case, we have to backtrack to make new choices. Once we
understand what the 729x324 matrix represents, the backtracking algorithm
itself is easy.
A major difference between the algorithm implemented here and Guenter
Stertenbrink's suexco.c lies in how to count the number of the available
choices for each constraint. Suexco.c computes the count with a loop, while
the algorithm here keeps the count in an array. The latter is a little more
complex to implement as we have to keep the counts synchronized all the time,
but it is 50-100% faster, depending on the input.
*/
// the sparse representation of the binary matrix
class sdaux_t {
uint16_t r[324][9]; // M(r[c][i], c) is a non-zero element
uint16_t c[729][4]; // M(r, c[r][j]) is a non-zero element
public:
sdaux_t();
int update(int8_t sr[729], uint8_t sc[324], int r, int v);
int solve(const char *_s);
};
// generate the sparse representation of the binary matrix
sdaux_t::sdaux_t() {
int i, j, k, r, c, c2, r2;
int8_t nr[324];
for (i = r = 0; i < 9; ++i) // generate c[729][4]
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k) // this "9" means each cell has 9 possible numbers
this->c[r][0] = 9 * i + j, // row-column constraint
this->c[r][1] = (i/3*3 + j/3) * 9 + k + 81, // box-number constraint
this->c[r][2] = 9 * i + k + 162, // row-number constraint
this->c[r][3] = 9 * j + k + 243, // col-number constraint
++r;
for (c = 0; c < 324; ++c) nr[c] = 0;
for (r = 0; r < 729; ++r) // generate r[][] from c[][]
for (c2 = 0; c2 < 4; ++c2)
k = this->c[r][c2], this->r[k][nr[k]++] = r;
}
// update the state vectors when we pick up choice r; v=1 for setting choice; v=-1 for reverting
int sdaux_t::update(int8_t sr[729], uint8_t sc[324], int r, int v)
{
int c2, min = 10, min_c = 0;
for (c2 = 0; c2 < 4; ++c2) sc[this->c[r][c2]] += v<<7;
for (c2 = 0; c2 < 4; ++c2) { // update # available choices
int r2, rr, cc2, c = this->c[r][c2];
if (v > 0) { // move forward
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = this->r[c][r2]]++ != 0) continue; // update the row status
for (cc2 = 0; cc2 < 4; ++cc2) {
int cc = this->c[rr][cc2];
if (--sc[cc] < min) // update # allowed choices
min = sc[cc], min_c = cc; // register the minimum number
}
}
} else { // revert
const uint16_t *p;
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = this->r[c][r2]] != 0) continue; // update the row status
p = this->c[rr]; ++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]]; // update the count array
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
// solve a Sudoku; _s is the standard dot/number representation
int sdaux_t::solve(const char *_s)
{
int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack
int8_t sr[729], cr[81]; // sr[r]: # times the row is forbidden by others; cr[i]: row chosen at step i
uint8_t sc[324]; // bit 1-7: # allowed choices; bit 8: the constraint has been used or not
int16_t cc[81]; // cc[i]: col chosen at step i
char out[82];
for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden
for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used
for (i = 0; i < 81; ++i) {
int a = _s[i] >= '1' && _s[i] <= '9'? _s[i] - '1' : -1; // number from -1 to 8
if (a >= 0) this->update(sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0) ++hints; // count the number of hints
cr[i] = cc[i] = -1, out[i] = _s[i];
}
for (i = 0, dir = 1, cand = 10<<16|0, out[81] = 0;;) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand>>16, cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c], cc[i] = c; // choose the top constraint
if (min <= 1) break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) this->update(sr, sc, this->r[c][cr[i]], -1); // revert the choice
for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make
if (sr[this->r[c][r2]] == 0) break; // found if the state equals 0
if (r2 < 9) {
cand = this->update(sr, sc, this->r[c][r2], 1); // set the choice
cr[i++] = r2; dir = 1; // moving forward
} else cr[i--] = dir = -1; // backtrack
}
if (i < 0) break;
for (j = 0; j < i; ++j) r = this->r[cc[j]][cr[j]], out[r/9] = r%9 + '1'; // print
//puts(out);
++n; --i; dir = -1; // backtrack
}
return n; // return the number of solutions
}
int main()
{
sdaux_t *a = new sdaux_t();
char buf[1024];
while (fgets(buf, 1024, stdin) != 0) {
if (strlen(buf) < 81) continue;
a->solve(buf);
//putchar('\n');
}
delete a;
return 0;
}
================================================
FILE: benchmarks/Sudoku/sudoku_cs.cs
================================================
using System;
class sudoku_v1 {
int[,] R, C;
public void genmat() {
R = new int[324,9];
C = new int[729,4];
int[] nr = new int[324];
int i, j, k, r, c, c2;
for (i = r = 0; i < 9; ++i) // generate c[729][4]
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k) { // this "9" means each cell has 9 possible numbers
C[r,0] = 9 * i + j; // row-column constraint
C[r,1] = (i/3*3 + j/3) * 9 + k + 81; // box-number constraint
C[r,2] = 9 * i + k + 162; // row-number constraint
C[r,3] = 9 * j + k + 243; // col-number constraint
++r;
}
for (c = 0; c < 324; ++c) nr[c] = 0;
for (r = 0; r < 729; ++r) // generate r[][] from c[][]
for (c2 = 0; c2 < 4; ++c2) {
k = C[r,c2]; R[k,nr[k]] = r; nr[k]++;
}
}
private int sd_update(int[] sr, int[] sc, int r, int v) {
int c2, min = 10, min_c = 0;
for (c2 = 0; c2 < 4; ++c2) sc[C[r,c2]] += v<<7;
for (c2 = 0; c2 < 4; ++c2) { // update # available choices
int r2, rr, cc2, c = C[r,c2];
if (v > 0) { // move forward
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = R[c,r2]]++ != 0) continue; // update the row status
for (cc2 = 0; cc2 < 4; ++cc2) {
int cc = C[rr,cc2];
if (--sc[cc] < min) { // update # allowed choices
min = sc[cc]; min_c = cc; // register the minimum number
}
}
}
} else { // revert
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = R[c,r2]] != 0) continue; // update the row status
++sc[C[rr,0]]; ++sc[C[rr,1]]; ++sc[C[rr,2]]; ++sc[C[rr,3]]; // update the count array
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
// solve a Sudoku; _s is the standard dot/number representation
public int solve(String _s) {
int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack
int[] sr = new int[729];
int[] cr = new int[81];
int[] sc = new int[324];
int[] cc = new int[81];
int[] o = new int[81];
for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden
for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used
for (i = 0; i < 81; ++i) {
int a = _s[i] >= '1' && _s[i] <= '9'? _s[i] - '1' : -1; // number from -1 to 8
if (a >= 0) sd_update(sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0) ++hints; // count the number of hints
cr[i] = cc[i] = -1; o[i] = a;
}
i = 0; dir = 1; cand = 10<<16|0;
for (;;) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand>>16; cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c]; cc[i] = c; // choose the top constraint
if (min <= 1) break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) sd_update(sr, sc, R[c,cr[i]], -1); // revert the choice
for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make
if (sr[R[c,r2]] == 0) break; // found if the state equals 0
if (r2 < 9) {
cand = sd_update(sr, sc, R[c,r2], 1); // set the choice
cr[i++] = r2; dir = 1; // moving forward
} else cr[i--] = dir = -1; // backtrack
}
if (i < 0) break;
char[] y = new char[81];
for (j = 0; j < 81; ++j) y[i] = (char)(o[i] + '1');
for (j = 0; j < i; ++j) { r = R[cc[j],cr[j]]; y[r/9] = (char)(r%9 + '1'); }
Console.WriteLine(new String(y));
++n; --i; dir = -1; // backtrack
}
return n;
}
public static void Main(String[] args) {
sudoku_v1 a = new sudoku_v1();
String l;
a.genmat();
while ((l = Console.ReadLine()) != null)
if (l.Length >= 81) {
a.solve(l);
Console.WriteLine();
}
}
}
================================================
FILE: benchmarks/Sudoku/sudoku_d.d
================================================
// Works with LDC1
// Compile with: ldc -O3 -release -inline
// Contributed by leonardo
/*
The MIT License
Copyright (c) 2011 by Attractive Chaos <attractor@live.co.uk>
leonardo
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This implements an improved algorithm of Guenter Stertenbrink's suexco.c
// (http://magictour.free.fr/suexco.txt).
import tango.stdc.stdio: puts, fgets, stdin, putchar;
import tango.stdc.string: strlen;
/// the sparse representation of the binary matrix
struct Sdaux {
int[9][324] r; // M(r[c][i], c) is a non-zero element
int[4][729] c; // M(r, c[r][j]) is a non-zero element
/// generate the sparse representation of the binary matrix
void initialize() { // static this() is slower
// generate this.c
{
int r1 = 0;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
for (int k = 0; k < 9; k++) { // this "9" means each cell has 9 possible numbers
c[r1][] = [9 * i + j, (i/3*3 + j/3) * 9 + k + 81, 9 * i + k + 162, 9 * j + k + 243];
r1++;
}
}
// generate this.r from this.c
byte[r.length] nr;
foreach (ushort r2, ref rowc; this.c)
foreach (c2, int k; rowc) {
this.r[k][nr[k]] = r2;
nr[k]++;
}
}
}
/// update the state vectors when we pick up choice r; v=1 for setting choice; v=-1 for reverting
int sdUpdate(in Sdaux* aux, byte[Sdaux.c.length] sr,
ubyte[Sdaux.r.length] sc, in int r, in int v) {
int min = 10, min_c;
for (size_t c2 = 0; c2 < aux.c[0].length; c2++)
sc[aux.c[r][c2]] += v << 7;
for (size_t c2 = 0; c2 < aux.c[0].length; c2++) { // update # available choices
int c = aux.c[r][c2];
int rr;
if (v > 0) { // move forward
for (size_t r2 = 0; r2 < 9; r2++) {
if (sr[rr = aux.r[c][r2]]++ != 0)
continue; // update the row status
for (size_t cc2 = 0; cc2 < aux.c[0].length; cc2++) {
int cc = aux.c[rr][cc2];
sc[cc]--;
if (sc[cc] < min) { // update # allowed choices
min = sc[cc]; // register the minimum number
min_c = cc;
}
}
}
} else { // revert
for (size_t r2 = 0; r2 < 9; r2++) {
if (--sr[rr = aux.r[c][r2]] != 0)
continue; // update the row status
auto p = aux.c[rr].ptr;
sc[p[0]]++; // update the count array
sc[p[1]]++;
sc[p[2]]++;
sc[p[3]]++;
}
}
}
return (min << 16) | min_c; // return the col that has been modified and
// with the minimal available choices
}
/// solve a Sudoku; _s is the standard dot/number representation
int sdSolve(in Sdaux* aux, in char* _s) {
int hints;
byte[Sdaux.c.length] sr; // sr[r]: # times the row is forbidden by others
byte[81] cr = -1; // cr[i]: row chosen at step i
ubyte[Sdaux.r.length] sc = 9; // bit 1-7: # allowed choices;
// bit 8: the constraint has been used or not
// 9 allowed choices; no constraint has been used
short[cr.length] cc = -1; // cc[i]: col chosen at step i
char[82] outs;
for (int i = 0; i < cr.length; i++) {
int a = (_s[i] >= '1' && _s[i] <= '9') ? (_s[i] - '1') : -1; // number from -1 to 8
if (a >= 0)
sdUpdate(aux, sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0)
hints++; // count the number of hints
outs[i] = _s[i];
}
int dir; // dir=1: forward; dir=-1: backtrack
int i, r, cand, n, min;
for (i = 0, dir = 1, cand = (10 << 16) | 0, outs[81] = 0; ; ) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand >> 16;
cc[i] = cand & 0xFFFF;
if (min > 1) {
for (size_t c = 0; c < sc.length; c++) { // performance-critical loop
if (sc[c] < min) {
min = sc[c]; // choose the top constraint
cc[i] = cast(short)c;
if (min <= 1)
break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) {
dir = cr[i] = -1; // backtrack
i--;
}
}
int c = cc[i];
if (dir == -1 && cr[i] >= 0)
sdUpdate(aux, sr, sc, aux.r[c][cr[i]], -1); // revert the choice
int r2;
for (r2 = cr[i] + 1; r2 < 9; r2++) // search for the choice to make
if (sr[aux.r[c][r2]] == 0)
break; // found if the state equals 0
if (r2 < 9) {
cand = sdUpdate(aux, sr, sc, aux.r[c][r2], 1); // set the choice
cr[i] = cast(byte)r2; // moving forward. r2 < 9
i++;
dir = 1;
} else {
dir = cr[i] = -1; // backtrack
i--;
}
}
if (i < 0)
break;
for (size_t j = 0; j < i; j++) {
r = aux.r[cc[j]][cr[j]];
outs[r / 9] = cast(char)(r % 9 + '1'); // print
}
puts(outs.ptr);
n++; // backtrack
i--;
dir = -1;
}
return n; // return the number of solutions
}
void main() {
Sdaux a;
a.initialize();
char[1024] buf;
while (fgets(buf.ptr, buf.length, stdin) != null) {
if (strlen(buf.ptr) < 81)
continue;
sdSolve(&a, buf.ptr);
putchar('\n');
}
}
================================================
FILE: benchmarks/Sudoku/sudoku_dart.dart
================================================
import 'dart:core';
import 'dart:io';
import 'dart:typeddata';
class Sudoku {
final _R = new List<Uint16List>(324);
final _C = new List<List<int>>(729);
Sudoku() {
final Uint8List nr = new Uint8List(324);
for (int i = 0, r = 0; i < 9; ++i)
for (int j = 0; j < 9; ++j)
for (int k = 0; k < 9; ++k)
_C[r++] = <int>[ 9 * i + j, (i~/3*3 + j~/3) * 9 + k + 81, 9 * i + k + 162, 9 * j + k + 243 ];
for (int c = 0; c < 324; ++c) {
_R[c] = new Uint16List(9);
nr[c] = 0;
}
for (int r = 0; r < 729; ++r)
for (int c2 = 0; c2 < 4; ++c2) {
int k = _C[r][c2];
_R[k][nr[k]++] = r;
}
}
_update(sr, sc, r, v) {
int min = 10, min_c = 0;
for (int c2 = 0; c2 < 4; ++c2) sc[_C[r][c2]] += v<<7;
for (int c2 = 0; c2 < 4; ++c2) {
int r2, rr, cc2, c = _C[r][c2];
if (v > 0) {
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = _R[c][r2]]++ != 0) continue;
for (cc2 = 0; cc2 < 4; ++cc2) {
var cc = _C[rr][cc2];
if (--sc[cc] < min) { min = sc[cc]; min_c = cc; }
}
}
} else { // revert
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = _R[c][r2]] != 0) continue;
var p = _C[rr];
++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]];
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
solve(s_) {
int j, r, c, r2, min, hints = 0;
var sr = new Int16List(729), sc = new Int16List(324);
var cr = new Int16List(81), cc = new Int16List(81), out = new Int16List(81);
List<String> ret = [];
for (r = 0; r < 729; ++r) sr[r] = 0;
for (c = 0; c < 324; ++c) sc[c] = 9;
for (int i = 0; i < 81; ++i) {
int a = s_.codeUnitAt(i) >= 49 && s_.codeUnitAt(i) <= 57? s_.codeUnitAt(i) - 49 : -1;
if (a >= 0) _update(sr, sc, i * 9 + a, 1);
if (a >= 0) ++hints;
cr[i] = cc[i] = -1; out[i] = a + 1;
}
for (int i = 0, dir = 1, cand = 10<<16|0;;) {
while (i >= 0 && i < 81 - hints) {
if (dir == 1) {
min = cand>>16; cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c]; cc[i] = c;
if (min <= 1) break;
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1;
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) _update(sr, sc, _R[c][cr[i]], -1);
for (r2 = cr[i] + 1; r2 < 9; ++r2)
if (sr[_R[c][r2]] == 0) break;
if (r2 < 9) {
cand = _update(sr, sc, _R[c][r2], 1);
cr[i++] = r2; dir = 1;
} else cr[i--] = dir = -1;
}
if (i < 0) break;
Uint8List y = new Uint8List(81);
for (j = 0; j < 81; ++j) y[j] = out[j];
for (j = 0; j < i; ++j) { r = _R[cc[j]][cr[j]]; y[r~/9] = r%9 + 1; }
ret.add(y.join());
--i; dir = -1;
}
return ret;
}
}
main()
{
final List<String> argv = new Options().arguments;
final fp = new File(argv[0]);
final lines = fp.readAsLinesSync(encoding: Encoding.ASCII);
final Sudoku s = new Sudoku();
for (int i = 0; i < lines.length; ++i) {
var rst = s.solve(lines[i]);
for (final x in rst) print(x);
print("");
}
}
================================================
FILE: benchmarks/Sudoku/sudoku_go.go
================================================
package main
import (
"bufio"
"fmt"
"os"
)
type sdaux_t struct {
r [324][9]uint16
c [729][4]uint16
}
func sd_genmat() *sdaux_t {
a := new(sdaux_t)
nr := make([]int8, 324)
r := 0
for i := 0; i < 9; i++ {
for j := 0; j < 9; j++ {
for k := 0; k < 9; k++ {
a.c[r][0] = uint16(9*i + j)
a.c[r][1] = uint16((i/3*3+j/3)*9 + k + 81)
a.c[r][2] = uint16(9*i + k + 162)
a.c[r][3] = uint16(9*j + k + 243)
r++
}
}
}
for c := 0; c < 324; c++ {
nr[c] = 0
}
for r := 0; r < 729; r++ {
for c2 := 0; c2 < 4; c2++ {
k := a.c[r][c2]
a.r[k][nr[k]] = uint16(r)
nr[k]++
}
}
return a
}
func sd_update_forward(aux *sdaux_t, sr []int8, sc []uint8, r uint16) int {
min, min_c := uint8(10), uint16(0)
rows := &aux.c[r]
for _, c := range rows {
sc[c] |= 0x80
}
for _, c := range rows {
for _, rr := range &aux.r[c] {
sr[rr]++
if sr[rr] != 1 {
continue
}
for _, cc := range &aux.c[rr] {
v := sc[cc] - 1
sc[cc] = v
if v < min {
min, min_c = v, cc
}
}
}
}
return int(min)<<16 | int(min_c)
}
func sd_update_revert(aux *sdaux_t, sr []int8, sc []uint8, r uint16) {
rows := &aux.c[r]
for _, c := range rows {
sc[c] &= 0x7f
}
for _, c := range rows {
for _, rr := range &aux.r[c] {
sr[rr]--
if sr[rr] != 0 {
continue
}
for _, cc := range &aux.c[rr] {
sc[cc]++
} // unroll this loop makes no difference
}
}
}
func sd_solve(aux *sdaux_t, _s []byte) int {
sr := make([]int8, 729)
cr := make([]int8, 81)
sc := make([]uint8, 324)
cc := make([]int16, 81)
out := make([]byte, 81)
n, hints := 0, 0
for c := 0; c < 324; c++ {
sc[c] = 9
}
for i := 0; i < 81; i++ {
a := -1
if _s[i] >= '1' && _s[i] <= '9' {
a = int(_s[i] - '1')
}
if a >= 0 {
sd_update_forward(aux, sr, sc, uint16(i*9+a))
hints++
}
cr[i], cc[i], out[i] = -1, -1, _s[i]
}
i, dir, cand := 0, 1, 10<<16
for {
for i >= 0 && i < 81-hints {
if dir == 1 {
min := uint8(cand >> 16)
cc[i] = int16(cand & 0xffff)
if min > 1 {
for c, scc := range sc {
if scc < min {
min, cc[i] = scc, int16(c)
if min <= 1 {
break
}
}
}
}
if min == 0 || min == 10 {
cr[i], dir = -1, -1
i--
}
}
c := cc[i]
if dir == -1 && cr[i] >= 0 {
sd_update_revert(aux, sr, sc, aux.r[c][cr[i]])
}
r2_ := 9
for r2 := cr[i] + 1; r2 < 9; r2++ {
if sr[aux.r[c][r2]] == 0 {
r2_ = int(r2)
break
}
}
if r2_ < 9 {
cand = sd_update_forward(aux, sr, sc, aux.r[c][r2_])
cr[i], dir = int8(r2_), 1
i++
} else {
cr[i], dir = -1, -1
i--
}
}
if i < 0 {
break
}
for j := 0; j < i; j++ {
r := aux.r[cc[j]][cr[j]]
out[r/9] = byte(r%9) + '1'
}
fmt.Println(string(out))
n++
i--
dir = -1
}
return n
}
func main() {
a := sd_genmat()
r := bufio.NewReader(os.Stdin)
for {
l, e := r.ReadSlice('\n')
if e != nil {
break
}
if len(l) > 81 {
sd_solve(a, l)
fmt.Println("")
}
}
}
================================================
FILE: benchmarks/Sudoku/sudoku_java.java
================================================
import java.io.*;
class sudoku_java {
int[][] R, C;
public void genmat() {
R = new int[324][9];
C = new int[729][4];
int[] nr = new int[324];
int i, j, k, r, c, c2, r2;
for (i = r = 0; i < 9; ++i) // generate c[729][4]
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k) { // this "9" means each cell has 9 possible numbers
C[r][0] = 9 * i + j; // row-column constraint
C[r][1] = (i/3*3 + j/3) * 9 + k + 81; // box-number constraint
C[r][2] = 9 * i + k + 162; // row-number constraint
C[r][3] = 9 * j + k + 243; // col-number constraint
++r;
}
for (c = 0; c < 324; ++c) nr[c] = 0;
for (r = 0; r < 729; ++r) // generate r[][] from c[][]
for (c2 = 0; c2 < 4; ++c2) {
k = C[r][c2]; R[k][nr[k]++] = r;
}
}
private int sd_update(int[] sr, int[] sc, int r, int v) {
int c2, min = 10, min_c = 0;
for (c2 = 0; c2 < 4; ++c2) sc[C[r][c2]] += v<<7;
for (c2 = 0; c2 < 4; ++c2) { // update # available choices
int r2, rr, cc2, c = C[r][c2];
if (v > 0) { // move forward
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = R[c][r2]]++ != 0) continue; // update the row status
for (cc2 = 0; cc2 < 4; ++cc2) {
int cc = C[rr][cc2];
if (--sc[cc] < min) { // update # allowed choices
min = sc[cc]; min_c = cc; // register the minimum number
}
}
}
} else { // revert
int[] p;
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = R[c][r2]] != 0) continue; // update the row status
p = C[rr]; ++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]]; // update the count array
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
// solve a Sudoku; _s is the standard dot/number representation
public int solve(String _s) {
int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack
int[] sr = new int[729];
int[] cr = new int[81];
int[] sc = new int[324];
int[] cc = new int[81];
int[] out = new int[81];
for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden
for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used
for (i = 0; i < 81; ++i) {
int a = _s.charAt(i) >= '1' && _s.charAt(i) <= '9'? _s.codePointAt(i) - '1' : -1; // number from -1 to 8
if (a >= 0) sd_update(sr, sc, i * 9 + a, 1); // set the choice
if (a >= 0) ++hints; // count the number of hints
cr[i] = cc[i] = -1; out[i] = a;
}
i = 0; dir = 1; cand = 10<<16|0;
for (;;) {
while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps
if (dir == 1) {
min = cand>>16; cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c]; cc[i] = c; // choose the top constraint
if (min <= 1) break; // this is for acceleration; slower without this line
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) sd_update(sr, sc, R[c][cr[i]], -1); // revert the choice
for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make
if (sr[R[c][r2]] == 0) break; // found if the state equals 0
if (r2 < 9) {
cand = sd_update(sr, sc, R[c][r2], 1); // set the choice
cr[i++] = r2; dir = 1; // moving forward
} else cr[i--] = dir = -1; // backtrack
}
if (i < 0) break;
char[] y = new char[81];
for (j = 0; j < 81; ++j) y[j] = (char)(out[j] + '1');
for (j = 0; j < i; ++j) { r = R[cc[j]][cr[j]]; y[r/9] = (char)(r%9 + '1'); }
//System.out.println(new String(y));
++n; --i; dir = -1; // backtrack
}
return n;
}
public static void main(String[] args) throws Exception {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
sudoku_java a = new sudoku_java();
String l;
a.genmat();
while ((l = stdin.readLine()) != null)
if (l.length() >= 81) {
a.solve(l);
//System.out.println();
}
}
}
================================================
FILE: benchmarks/Sudoku/sudoku_javascript.js
================================================
function Sudoku() {
var C = [], R = [];
function sd_genmat() { // precompute matrix
var i, j, r, c, c2;
for (i = r = 0; i < 9; ++i)
for (j = 0; j < 9; ++j)
for (k = 0; k < 9; ++k)
C[r++] = [ 9 * i + j, (Math.floor(i/3)*3 + Math.floor(j/3)) * 9 + k + 81, 9 * i + k + 162, 9 * j + k + 243 ]
for (c = 0; c < 324; ++c) R[c] = []
for (r = 0; r < 729; ++r)
for (c2 = 0; c2 < 4; ++c2)
R[C[r][c2]].push(r)
}
function sd_update(sr, sc, r, v) { // update
var min = 10, min_c = 0;
for (var c2 = 0; c2 < 4; ++c2) sc[C[r][c2]] += v<<7;
for (var c2 = 0; c2 < 4; ++c2) {
var r2, rr, cc2, c = C[r][c2];
if (v > 0) {
for (r2 = 0; r2 < 9; ++r2) {
if (sr[rr = R[c][r2]]++ != 0) continue;
for (cc2 = 0; cc2 < 4; ++cc2) {
var cc = C[rr][cc2];
if (--sc[cc] < min)
min = sc[cc], min_c = cc;
}
}
} else { // revert
for (r2 = 0; r2 < 9; ++r2) {
if (--sr[rr = R[c][r2]] != 0) continue;
var p = C[rr]
++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]];
}
}
}
return min<<16 | min_c; // return the col that has been modified and with the minimal available choices
}
sd_genmat();
return function(_s) { // closure, the actual solver
var i, j, r, c, r2, min, cand, dir, hints = 0;
var sr = [], sc = [], cr = [], cc = [], out = [], ret = [];
for (r = 0; r < 729; ++r) sr[r] = 0;
for (c = 0; c < 324; ++c) sc[c] = 9;
for (i = 0; i < 81; ++i) {
var a = _s.charAt(i) >= '1' && _s.charAt(i) <= '9'? _s.charCodeAt(i) - 49 : -1;
if (a >= 0) sd_update(sr, sc, i * 9 + a, 1);
if (a >= 0) ++hints;
cr[i] = cc[i] = -1, out[i] = a + 1;
}
for (i = 0, dir = 1, cand = 10<<16|0;;) {
while (i >= 0 && i < 81 - hints) {
if (dir == 1) {
min = cand>>16, cc[i] = cand&0xffff;
if (min > 1) {
for (c = 0; c < 324; ++c) {
if (sc[c] < min) {
min = sc[c], cc[i] = c;
if (min <= 1) break;
}
}
}
if (min == 0 || min == 10) cr[i--] = dir = -1;
}
c = cc[i];
if (dir == -1 && cr[i] >= 0) sd_update(sr, sc, R[c][cr[i]], -1);
for (r2 = cr[i] + 1; r2 < 9; ++r2)
if (sr[R[c][r2]] == 0) break;
if (r2 < 9) {
cand = sd_update(sr, sc, R[c][r2], 1);
cr[i++] = r2; dir = 1;
} else cr[i--] = dir = -1;
}
if (i < 0) break;
var y = [];
for (j = 0; j < 81; ++j) y[j] = out[j];
for (j = 0; j < i; ++j) r = R[cc[j]][cr[j]], y[Math.floor(r/9)] = r%9 + 1;
ret.push(y);
--i; dir = -1;
}
return ret;
}
}
var solver = Sudoku();
function processLine (l) {
if (l.length >= 81) {
var r = solver(l)
//for (var i = 0; i < r.length; ++i) print(r[i].join('')+'\n')
}
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
processLine(line);
})
================================================
FILE: benchmarks/Sudoku/sudoku_lua.lua
================================================
function sd_genmat()
local R, C, r = {}, {}, 0
for i = 0, 8 do
for j = 0, 8 do
for k = 0, 8 do
C[r], r = { 9 * i + j, math.floor(i/3)*27 + math.floor(j/3)*9 + k + 81,
9 * i + k + 162, 9 * j + k + 243 }, r + 1
end
end
end
for c = 0, 323 do R[c] = {} end
for r = 0, 728 do
for c2 = 1, 4 do table.insert(R[C[r][c2]], r) end
end
return R, C
end
function sd_update(R, C, sr, sc, r, v)
local min, min_c = 10, 0
for c2 = 1, 4 do
if v > 0 then sc[C[r][c2]] = sc[C[r][c2]] + 128
else sc[C[r][c2]] = sc[C[r][c2]] - 128 end
end
for c2 = 1, 4 do
local c = C[r][c2]
if v > 0 then
for r2 = 1, 9 do
local rr = R[c][r2]
sr[rr] = sr[rr] + 1
if sr[rr] == 1 then
for cc2 = 1, 4 do
local cc = C[rr][cc2]
sc[cc] = sc[cc] - 1
if sc[cc] < min then min, min_c = sc[cc], cc end
end
end
end
else
for r2 = 1, 9 do
local rr = R[c][r2]
sr[rr] = sr[rr] - 1
if sr[rr] == 0 then
local p = C[rr]
sc[p[1]], sc[p[2]], sc[p[3]], sc[p[4]] = sc[p[1]]+1, sc[p[2]]+1, sc[p[3]]+1, sc[p[4]]+1
end
end
end
end
return min, min_c
end
function sd_solve(R, C, s)
local sr, sc, cr, cc, hints = {}, {}, {}, {}, 0
for r = 0, 728 do sr[r] = 0 end
for c = 0, 323 do sc[c] = 9 end
for i = 0, 80 do
local t = s:byte(i+1)
local a = t >= 49 and t <= 57 and t - 49 or -1
if a >= 0 then sd_update(R, C, sr, sc, i * 9 + a, 1); hints = hints + 1 end
cr[i], cc[i] = 0, 0
end
local i, min, dir, ret = 0, 10, 1, {}
while true do
while i >= 0 and i < 81 - hints do
if dir == 1 then
if min > 1 then
for c = 0, 323 do
if sc[c] < min then
min, cc[i] = sc[c], c
if min < 2 then break end
end
end
end
if min == 0 or min == 10 then cr[i], dir, i = 0, -1, i - 1 end
end
local c, r2_ = cc[i], 10
if dir == -1 and cr[i] > 0 then sd_update(R, C, sr, sc, R[c][cr[i]], -1) end
for r2 = cr[i] + 1, 9 do
if sr[R[c][r2]] == 0 then r2_ = r2; break end
end
if r2_ < 10 then
min, cc[i+1] = sd_update(R, C, sr, sc, R[c][r2_], 1)
cr[i], dir, i = r2_, 1, i + 1
else cr[i], dir, i = 0, -1, i - 1 end
end
if i < 0 then break end
local y = {}
for j = 1, 81 do y[j] = s:byte(j) - 48 end
for j = 0, i - 1 do
r = R[cc[j]][cr[j]]
y[math.floor(r/9)+1] = math.fmod(r, 9) + 1
end
ret[#ret+1] = y
dir, i = -1, i - 1
end
return ret
end
local R, C = sd_genmat()
for l in io.lines() do
if #l >= 81 then
local ret = sd_solve(R, C, l)
--for _, v in ipairs(ret) do print(table.concat(v)) end
--print()
end
end
================================================
FILE: benchmarks/Sudoku/sudoku_perl.pl
================================================
use strict;
use warnings;
my @aux = &sd_genmat();
while (<>) {
chomp;
if (length($_) >= 81) {
my $ret = &sd_solve($aux[0], $aux[1], $_);
print($_, "\n") for (@$ret);
print("\n");
}
}
sub sd_genmat() {
my (@C, @R);
for my $i (0..8) {
for my $j (0..8) {
for my $k (0..8) {
push(@C, [9*$i+$j, int($i/3)*27+int($j/3)*9+$k+81, 9*$i+$k+162, 9*$j+$k+243])
}
}
}
for my $r (0..728) {
for my $k (@{$C[$r]}) {
push(@{$R[$k]}, $r);
}
}
return (\@R, \@C);
}
sub sd_update() {
my ($R, $C, $sr, $sc, $r, $v) = @_;
my ($min, $min_c) = (10, 0);
for my $c (@{$C->[$r]}) {
if ($v > 0) { $sc->[$c] += 128; }
else { $sc->[$c] -= 128; }
}
for my $c (@{$C->[$r]}) {
if ($v > 0) {
for my $rr (@{$R->[$c]}) {
++$sr->[$rr];
next if ($sr->[$rr] != 1);
for my $cc (@{$C->[$rr]}) {
if (--$sc->[$cc] < $min) {
$min = $sc->[$cc];
$min_c = $cc;
}
}
}
} else {
for my $rr (@{$R->[$c]}) {
--$sr->[$rr];
next if ($sr->[$rr] != 0);
my $p = $C->[$rr];
++$sc->[$p->[0]]; ++$sc->[$p->[1]]; ++$sc->[$p->[2]]; ++$sc->[$p->[3]];
}
}
}
return $min<<16 | $min_c;
}
sub sd_solve() {
my ($R, $C, $s) = @_;
my (@sr, @sc, @cr, @cc, @ret);
my $hints = 0;
for my $r (0..728) { $sr[$r] = 0; }
for my $c (0..323) { $sc[$c] = 9; }
for my $i (0..80) {
my $a = substr($s, $i, 1) =~ /[1-9]/? ord(substr($s, $i, 1)) - 49 : -1;
if ($a >= 0) {
&sd_update($R, $C, \@sr, \@sc, $i*9+$a, 1);
++$hints;
}
$cr[$i] = $cc[$i] = -1;
}
#for my $i (0..323) {print("$i\t$sc[$i]\n")}
my ($i, $dir, $cand) = (0, 1, 10<<16);
for (;;) {
while ($i >= 0 && $i < 81 - $hints) {
if ($dir == 1) {
my $min = $cand>>16;
$cc[$i] = $cand&0xffff;
if ($min > 1) {
for my $c (0..323) {
if ($sc[$c] < $min) {
$min = $sc[$c];
$cc[$i] = $c;
last if ($min <= 1);
}
}
}
if ($min == 0 || $min == 10) {
$cr[$i--] = $dir = -1;
}
}
my $c = $cc[$i];
&sd_update($R, $C, \@sr, \@sc, $R->[$c][$cr[$i]], -1) if ($dir == -1 && $cr[$i] >= 0);
my $r2;
for ($r2 = $cr[$i] + 1; $r2 < 9; ++$r2) {
last if ($sr[$R->[$c][$r2]] == 0);
}
if ($r2 < 9) {
$cand = &sd_update($R, $C, \@sr, \@sc, $R->[$c][$r2], 1);
$cr[$i++] = $r2; $dir = 1;
} else {
$cr[$i--] = $dir = -1;
}
}
last if ($i < 0);
for my $j (0..$i-1) {
my $r = $R->[$cc[$j]][$cr[$j]];
substr($s, int($r/9), 1) = $r%9 + 1;
}
push(@ret, $s);
--$i; $dir = -1;
}
return \@ret;
}
================================================
FILE: benchmarks/Sudoku/sudoku_python.py
================================================
import sys, string
try:
xrange(1)
except NameError:
xrange = range
def sd_genmat():
C = [[n/9, n/81*9 + n%9 + 81, n%81 + 162, n%9*9 + n/243*3 + n/27%3 + 243] for n in range(729)]
R = [[] for c in xrange(324)]
for r in xrange(729):
for c2 in xrange(4):
R[C[r][c2]].append(r)
return R, C
def sd_update(R, C, sr, sc, r, v):
m = 10
m_c = 0
for c in C[r]: sc[c] += v<<7
for c in C[r]:
if v > 0:
for rr in R[c]:
sr[rr] += 1
if sr[rr] == 1:
for cc in C[rr]:
sc[cc] -= 1
if sc[cc] < m:
m, m_c = sc[cc], cc
else:
for rr in R[c]:
sr[rr] -= 1
if sr[rr] == 0:
p = C[rr]
sc[p[0]] += 1; sc[p[1]] += 1; sc[p[2]] += 1; sc[p[3]] += 1;
return m, m_c
def sd_solve(R, C, s):
ret, out, hints = [], [], 0
sr = [0] * 729
sc = [9] * 324
cr = [-1] * 81
cc = [-1] * 81
for i in xrange(81):
if ord(s[i]) >= 49 and ord(s[i]) <= 57: a = ord(s[i]) - 49
else: a = -1
if a >= 0:
sd_update(R, C, sr, sc, i * 9 + a, 1)
hints += 1
out.append(a + 1)
i, m, d = 0, 10, 1
while True:
while i >= 0 and i < 81 - hints:
if d == 1:
if m > 1:
for c in xrange(324): # using enumerate() here is slower
if sc[c] < m:
m, cc[i] = sc[c], c
if m < 2: break
if m == 0 or m == 10:
cr[i], d = -1, -1
i -= 1
c = cc[i]
if d == -1 and cr[i] >= 0: sd_update(R, C, sr, sc, R[c][cr[i]], -1)
r2_ = 9
for r2 in xrange(cr[i] + 1, 9):
if sr[R[c][r2]] == 0: r2_ = r2; break
if r2_ < 9:
m, cc[i+1] = sd_update(R, C, sr, sc, R[c][r2], 1)
cr[i], d = r2, 1
i += 1
else:
cr[i], d = -1, -1
i -= 1
if i < 0: break
y = out[:81]
for j in xrange(i):
r = R[cc[j]][cr[j]]
y[r//9] = r%9 + 1
ret.append(y)
i -= 1
d = -1
return ret
R, C = sd_genmat()
for line in sys.stdin:
if len(line) >= 81:
ret = sd_solve(R, C, line)
#for j in ret:
# print(''.join(map(str, j)))
#print('')
================================================
FILE: benchmarks/Sudoku/sudoku_ruby.rb
================================================
def sd_genmat()
mr = Array.new(324) { [] }
mc = Array.new(729) { [] }
r = 0
(0...9).each do |i|
(0...9).each do |j|
(0...9).each do |k|
mc[r] = [ 9 * i + j, (i/3*3 + j/3) * 9 + k + 81, 9 * i + k + 162, 9 * j + k + 243 ]
r += 1
end
end
end
(0...729).each do |r|
(0...4).each do |c2|
mr[mc[r][c2]].push(r)
end
end
return mr, mc
end
def sd_update(mr, mc, sr, sc, r, v)
min, min_c = 10, 0
(0...4).each do |c2|
if v > 0 then sc[mc[r][c2]] += 128
else sc[mc[r][c2]] -= 128 end
end
(0...4).each do |c2|
c = mc[r][c2]
if v > 0 then
(0...9).each do |r2|
rr = mr[c][r2]
sr[rr] += + 1
if sr[rr] == 1 then
p = mc[rr]
sc[p[0]] -= 1; sc[p[1]] -= 1; sc[p[2]] -= 1; sc[p[3]] -= 1
if sc[p[0]] < min then min, min_c = sc[p[0]], p[0] end
if sc[p[1]] < min then min, min_c = sc[p[1]], p[1] end
if sc[p[2]] < min then min, min_c = sc[p[2]], p[2] end
if sc[p[3]] < min then min, min_c = sc[p[3]], p[3] end
end
end
else
(0...9).each do |r2|
rr = mr[c][r2]
sr[rr] -= 1
if sr[rr] == 0 then
p = mc[rr]
sc[p[0]] += 1; sc[p[1]] += 1; sc[p[2]] += 1; sc[p[3]] += 1
end
end
end
end
return min, min_c
end
def sd_solve(mr, mc, s)
ret, sr, sc, hints = [], Array.new(729) { 0 }, Array.new(324) { 9 }, 0
(0...81).each do |i|
a = (s[i].chr >= '1' and s[i].chr <= '9')? s[i].ord - 49 : -1
if a >= 0 then sd_update(mr, mc, sr, sc, i * 9 + a, 1); hints += 1 end
end
cr, cc = Array.new(81) { -1 }, Array.new(81) { 0 }
i, min, dir = 0, 10, 1
loop do
while i >= 0 and i < 81 - hints do
if dir == 1 then
if min > 1 then
(0...324).each do |c|
if sc[c] < min then
min, cc[i] = sc[c], c
if min < 2 then break end
end
end
end
if min == 0 or min == 10 then cr[i], dir, i = -1, -1, i - 1 end
end
c = cc[i]
if dir == -1 and cr[i] >= 0 then sd_update(mr, mc, sr, sc, mr[c][cr[i]], -1) end
r2_ = 9
(cr[i]+1...9).each do |r2|
if sr[mr[c][r2]] == 0 then r2_ = r2; break end
end
if r2_ < 9 then
min, cc[i+1] = sd_update(mr, mc, sr, sc, mr[c][r2_], 1)
cr[i], dir, i = r2_, 1, i + 1
else cr[i], dir, i = -1, -1, i - 1 end
end
if i < 0 then break end
o = []
(0...81).each do |j| o.push(s[j].ord - 49) end
(0...i).each do |j|
r = mr[cc[j]][cr[j]]
o[r/9] = r % 9 + 1
end
ret.push(o)
i, dir = i - 1, -1
end
return ret
end
mr, mc = sd_genmat()
STDIN.each do |line|
if line.length >= 81 then
ret = sd_solve(mr, mc, line)
#ret.each do |s| puts s.join end
#puts
end
end
================================================
FILE: benchmarks/benchmark
================================================
gcc ./ext/genint.c -o ./ext/genint
gcc Nbodies/nbodies_c.c -std=c99 -O3 -lm -o Nbodies/nbodies_c
g++ Nbodies/nbodies_cpp.cpp -std=c++11 -O3 -lm -o Nbodies/nbodies_cpp
gcc Nbodies/nbodies_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -pg -O3 -lm -lpthread -o Nbodies/nbodies_cello
javac Nbodies/nbodies_java.java
gcc List/list_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o List/list_c
g++ List/list_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o List/list_cpp
gcc List/list_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -pg -O3 -lm -lpthread -o List/list_cello
javac List/list_java.java
gcc Dict/dict_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Dict/dict_c
g++ Dict/dict_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Dict/dict_cpp
gcc Dict/dict_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -pg -O3 -lm -lpthread -o Dict/dict_cello
javac Dict/dict_java.java
gcc Map/map_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Map/map_c
g++ Map/map_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Map/map_cpp
gcc Map/map_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -pg -O3 -lm -lpthread -o Map/map_cello
javac Map/map_java.java
gcc Sudoku/sudoku_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Sudoku/sudoku_c
g++ Sudoku/sudoku_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Sudoku/sudoku_cpp
gcc Sudoku/sudoku_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -pg -O3 -lm -lpthread -o Sudoku/sudoku_cello
javac Sudoku/sudoku_java.java
gcc Matmul/matmul_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Matmul/matmul_c
g++ Matmul/matmul_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Matmul/matmul_cpp
gcc Matmul/matmul_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -pg -O3 -lm -lpthread -o Matmul/matmul_cello
javac Matmul/matmul_java.java
gcc GC/gc_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o GC/gc_c
g++ GC/gc_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o GC/gc_cpp
gcc GC/gc_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -O3 -lm -lpthread -o GC/gc_cello
javac GC/gc_java.java
echo
echo "## Garbage Collection"
echo
echo -n "* C: "
time -f "%e" ./GC/gc_c
echo -n "* C++: "
time -f "%e" ./GC/gc_cpp
echo -n "* Cello: "
time -f "%e" ./GC/gc_cello
echo -n "* Java: "
time -f "%e" java -cp ./GC gc_java
echo -n "* Javascript: "
time -f "%e" nodejs GC/gc_javascript.js
echo -n "* Python: "
time -f "%e" python GC/gc_python.py
echo -n "* Ruby: "
time -f "%e" ruby GC/gc_ruby.rb
echo -n "* Lua: "
time -f "%e" lua GC/gc_lua.lua
echo -n "* Lua JIT: "
time -f "%e" luajit GC/gc_lua.lua
gprof GC/gc_cello > GC/profile.txt
rm gmon.out
echo
echo "## List"
echo
echo -n "* C: "
time -f "%e" ./List/list_c
echo -n "* C++: "
time -f "%e" ./List/list_cpp
echo -n "* Cello: "
time -f "%e" ./List/list_cello
echo -n "* Java: "
time -f "%e" java -cp ./List list_java
echo -n "* Javascript: "
time -f "%e" nodejs List/list_javascript.js
echo -n "* Python: "
time -f "%e" python List/list_python.py
echo -n "* Ruby: "
time -f "%e" ruby List/list_ruby.rb
echo -n "* Lua: "
time -f "%e" lua List/list_lua.lua
echo -n "* Lua JIT: "
time -f "%e" luajit List/list_lua.lua
gprof List/list_cello > List/profile.txt
rm gmon.out
echo
echo "## Map"
echo
echo -n "* C: "
time -f "%e" sh -c './ext/genint | ./Map/map_c'
echo -n "* C++: "
time -f "%e" sh -c './ext/genint | ./Map/map_cpp'
echo -n "* Cello: "
time -f "%e" sh -c './ext/genint | ./Map/map_cello'
echo -n "* Java: "
time -f "%e" sh -c './ext/genint | java -cp ./Map map_java'
echo -n "* Javascript: "
time -f "%e" sh -c './ext/genint | nodejs Map/map_javascript.js'
echo -n "* Python: "
time -f "%e" sh -c './ext/genint | python Map/map_python.py'
echo -n "* Ruby: "
time -f "%e" sh -c './ext/genint | ruby Map/map_ruby.rb'
echo -n "* Lua: "
time -f "%e" sh -c './ext/genint | lua Map/map_lua.lua'
echo -n "* Lua JIT: "
time -f "%e" sh -c './ext/genint | luajit Map/map_lua.lua'
gprof Map/map_cello > Map/profile.txt
rm gmon.out
echo
echo "## NBodies"
echo
echo -n "* C: "
time -f "%e" ./Nbodies/nbodies_c
echo -n "* C++: "
time -f "%e" ./Nbodies/nbodies_cpp
echo -n "* Cello: "
time -f "%e" ./Nbodies/nbodies_cello
echo -n "* Java: "
time -f "%e" java -cp ./Nbodies nbodies_java
echo -n "* Javascript: "
time -f "%e" nodejs Nbodies/nbodies_javascript.js
echo -n "* Python: "
time -f "%e" python Nbodies/nbodies_python.py
echo -n "* Ruby: "
time -f "%e" ruby Nbodies/nbodies_ruby.rb
echo -n "* Lua: "
time -f "%e" lua Nbodies/nbodies_lua.lua
echo -n "* Lua JIT: "
time -f "%e" luajit Nbodies/nbodies_lua.lua
gprof Nbodies/nbodies_cello > Nbodies/profile.txt
rm gmon.out
echo
echo "## Dict"
echo
echo -n "* C: "
time -f "%e" sh -c './ext/genint | ./Dict/dict_c'
echo -n "* C++: "
time -f "%e" sh -c './ext/genint | ./Dict/dict_cpp'
echo -n "* Cello: "
time -f "%e" sh -c './ext/genint | ./Dict/dict_cello'
echo -n "* Java: "
time -f "%e" sh -c './ext/genint | java -cp ./Dict dict_java'
echo -n "* Javascript: "
time -f "%e" sh -c './ext/genint | nodejs Dict/dict_javascript.js'
echo -n "* Python: "
time -f "%e" sh -c './ext/genint | python Dict/dict_python.py'
echo -n "* Ruby: "
time -f "%e" sh -c './ext/genint | ruby Dict/dict_ruby.rb'
echo -n "* Lua: "
time -f "%e" sh -c './ext/genint | lua Dict/dict_lua.lua'
echo -n "* Lua JIT: "
time -f "%e" sh -c './ext/genint | luajit Dict/dict_lua.lua'
gprof Dict/dict_cello > Dict/profile.txt
rm gmon.out
echo
echo "## Sudoku"
echo
echo -n "* C: "
time -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_c'
echo -n "* C++: "
time -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cpp'
echo -n "* Cello: "
time -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cello'
echo -n "* Java: "
time -f "%e" sh -c './ext/sudoku | java -cp ./Sudoku sudoku_java'
echo -n "* Javascript: "
time -f "%e" sh -c './ext/sudoku | nodejs Sudoku/sudoku_javascript.js'
echo -n "* Python: "
time -f "%e" sh -c './ext/sudoku | python Sudoku/sudoku_python.py'
echo -n "* Ruby: "
time -f "%e" sh -c './ext/sudoku | ruby Sudoku/sudoku_ruby.rb'
echo -n "* Lua: "
time -f "%e" sh -c './ext/sudoku | lua Sudoku/sudoku_lua.lua'
echo -n "* Lua JIT: "
time -f "%e" sh -c './ext/sudoku | luajit Sudoku/sudoku_lua.lua'
gprof Sudoku/sudoku_cello > Sudoku/profile.txt
rm gmon.out
echo
echo "## Matmul"
echo
echo -n "* C: "
time -f "%e" ./Matmul/matmul_c
echo -n "* C++: "
time -f "%e" ./Matmul/matmul_cpp
echo -n "* Cello: "
time -f "%e" ./Matmul/matmul_cello
echo -n "* Java: "
time -f "%e" java -cp ./Matmul matmul_java
echo -n "* Javascript: "
time -f "%e" nodejs Matmul/matmul_javascript.js
echo -n "* Python: "
time -f "%e" python Matmul/matmul_python.py
echo -n "* Ruby: "
time -f "%e" ruby Matmul/matmul_ruby.rb
echo -n "* Lua: "
time -f "%e" lua Matmul/matmul_lua.lua
echo -n "* Lua JIT: "
time -f "%e" luajit Matmul/matmul_lua.lua
gprof Matmul/matmul_cello > Matmul/profile.txt
rm gmon.out
================================================
FILE: benchmarks/benchmark.sh
================================================
#!/bin/sh
gcc ./ext/genint.c -o ./ext/genint
gcc Nbodies/nbodies_c.c -std=c99 -O3 -lm -o Nbodies/nbodies_c
g++ Nbodies/nbodies_cpp.cpp -std=c++11 -O3 -lm -o Nbodies/nbodies_cpp
cc Nbodies/nbodies_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -O3 -lm -lpthread -o Nbodies/nbodies_cello
javac Nbodies/nbodies_java.java
gcc List/list_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o List/list_c
g++ List/list_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o List/list_cpp
cc List/list_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o List/list_cello
javac List/list_java.java
gcc Dict/dict_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Dict/dict_c
g++ Dict/dict_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Dict/dict_cpp
cc Dict/dict_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Dict/dict_cello
javac Dict/dict_java.java
gcc Map/map_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Map/map_c
g++ Map/map_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Map/map_cpp
cc Map/map_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Map/map_cello
javac Map/map_java.java
gcc Sudoku/sudoku_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Sudoku/sudoku_c
g++ Sudoku/sudoku_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Sudoku/sudoku_cpp
cc Sudoku/sudoku_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Sudoku/sudoku_cello
javac Sudoku/sudoku_java.java
gcc Matmul/matmul_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Matmul/matmul_c
g++ Matmul/matmul_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Matmul/matmul_cpp
cc Matmul/matmul_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Matmul/matmul_cello
javac Matmul/matmul_java.java
gcc GC/gc_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o GC/gc_c
g++ GC/gc_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o GC/gc_cpp
cc GC/gc_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -O3 -lm -lpthread -o GC/gc_cello
javac GC/gc_java.java
echo
echo "## Garbage Collection"
echo
printf "* C: "
gtime -f "%e" -f "%e" ./GC/gc_c
printf "* C++: "
gtime -f "%e" -f "%e" ./GC/gc_cpp
printf "* Cello: "
gtime -f "%e" -f "%e" ./GC/gc_cello
printf "* Java: "
gtime -f "%e" -f "%e" java -cp ./GC gc_java
printf "* Javascript: "
gtime -f "%e" -f "%e" node GC/gc_javascript.js
printf "* Python: "
gtime -f "%e" -f "%e" python GC/gc_python.py
printf "* Ruby: "
gtime -f "%e" -f "%e" ruby GC/gc_ruby.rb
printf "* Lua: "
gtime -f "%e" -f "%e" lua GC/gc_lua.lua
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" luajit GC/gc_lua.lua
# gprof GC/gc_cello > GC/profile.txt
# rm gmon.out
echo
echo "## List"
echo
printf "* C: "
gtime -f "%e" -f "%e" ./List/list_c
printf "* C++: "
gtime -f "%e" -f "%e" ./List/list_cpp
printf "* Cello: "
gtime -f "%e" -f "%e" ./List/list_cello
printf "* Java: "
gtime -f "%e" -f "%e" java -cp ./List list_java
printf "* Javascript: "
gtime -f "%e" -f "%e" node List/list_javascript.js
printf "* Python: "
gtime -f "%e" -f "%e" python List/list_python.py
printf "* Ruby: "
gtime -f "%e" -f "%e" ruby List/list_ruby.rb
printf "* Lua: "
gtime -f "%e" -f "%e" lua List/list_lua.lua
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" luajit List/list_lua.lua
# gprof List/list_cello > List/profile.txt
# rm gmon.out
echo
echo "## Map"
echo
printf "* C: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_c'
printf "* C++: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_cpp'
printf "* Cello: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_cello'
printf "* Java: "
gtime -f "%e" -f "%e" sh -c './ext/genint | java -cp ./Map map_java'
printf "* Javascript: "
gtime -f "%e" -f "%e" sh -c './ext/genint | node Map/map_javascript.js'
printf "* Python: "
gtime -f "%e" -f "%e" sh -c './ext/genint | python Map/map_python.py'
printf "* Ruby: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ruby Map/map_ruby.rb'
printf "* Lua: "
gtime -f "%e" -f "%e" sh -c './ext/genint | lua Map/map_lua.lua'
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" sh -c './ext/genint | luajit Map/map_lua.lua'
# gprof Map/map_cello > Map/profile.txt
# rm gmon.out
echo
echo "## NBodies"
echo
printf "* C: "
gtime -f "%e" -f "%e" ./Nbodies/nbodies_c
printf "* C++: "
gtime -f "%e" -f "%e" ./Nbodies/nbodies_cpp
printf "* Cello: "
gtime -f "%e" -f "%e" ./Nbodies/nbodies_cello
printf "* Java: "
gtime -f "%e" -f "%e" java -cp ./Nbodies nbodies_java
printf "* Javascript: "
gtime -f "%e" -f "%e" node Nbodies/nbodies_javascript.js
printf "* Python: "
gtime -f "%e" -f "%e" python Nbodies/nbodies_python.py
printf "* Ruby: "
gtime -f "%e" -f "%e" ruby Nbodies/nbodies_ruby.rb
printf "* Lua: "
gtime -f "%e" -f "%e" lua Nbodies/nbodies_lua.lua
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" luajit Nbodies/nbodies_lua.lua
# gprof Nbodies/nbodies_cello > Nbodies/profile.txt
# rm gmon.out
echo
echo "## Dict"
echo
printf "* C: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_c'
printf "* C++: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_cpp'
printf "* Cello: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_cello'
printf "* Java: "
gtime -f "%e" -f "%e" sh -c './ext/genint | java -cp ./Dict dict_java'
printf "* Javascript: "
gtime -f "%e" -f "%e" sh -c './ext/genint | node Dict/dict_javascript.js'
printf "* Python: "
gtime -f "%e" -f "%e" sh -c './ext/genint | python Dict/dict_python.py'
printf "* Ruby: "
gtime -f "%e" -f "%e" sh -c './ext/genint | ruby Dict/dict_ruby.rb'
printf "* Lua: "
gtime -f "%e" -f "%e" sh -c './ext/genint | lua Dict/dict_lua.lua'
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" sh -c './ext/genint | luajit Dict/dict_lua.lua'
# gprof Dict/dict_cello > Dict/profile.txt
# rm gmon.out
echo
echo "## Sudoku"
echo
printf "* C: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_c'
printf "* C++: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cpp'
printf "* Cello: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cello'
printf "* Java: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | java -cp ./Sudoku sudoku_java'
printf "* Javascript: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | node Sudoku/sudoku_javascript.js'
printf "* Python: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | python Sudoku/sudoku_python.py'
printf "* Ruby: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | ruby Sudoku/sudoku_ruby.rb'
printf "* Lua: "
gtime -f "%e" -f "%e" sh -c './ext/sudoku | lua Sudoku/sudoku_lua.lua'
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" sh -c './ext/sudoku | luajit Sudoku/sudoku_lua.lua'
# gprof Sudoku/sudoku_cello > Sudoku/profile.txt
# rm gmon.out
echo
echo "## Matmul"
echo
printf "* C: "
gtime -f "%e" -f "%e" ./Matmul/matmul_c
printf "* C++: "
gtime -f "%e" -f "%e" ./Matmul/matmul_cpp
printf "* Cello: "
gtime -f "%e" -f "%e" ./Matmul/matmul_cello
printf "* Java: "
gtime -f "%e" -f "%e" java -cp ./Matmul matmul_java
printf "* Javascript: "
gtime -f "%e" -f "%e" node Matmul/matmul_javascript.js
printf "* Python: "
gtime -f "%e" -f "%e" python Matmul/matmul_python.py
printf "* Ruby: "
gtime -f "%e" -f "%e" ruby Matmul/matmul_ruby.rb
printf "* Lua: "
gtime -f "%e" -f "%e" lua Matmul/matmul_lua.lua
# printf "* Lua JIT: "
# gtime -f "%e" -f "%e" luajit Matmul/matmul_lua.lua
# gprof Matmul/matmul_cello > Matmul/profile.txt
# rm gmon.out
================================================
FILE: benchmarks/ext/cleantxt.c
================================================
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
FILE *fp;
int c = EOF;
if (argc == 1) {
fprintf(stderr, "Usage: cleantxt <file>\n");
return 1;
}
fp = strcmp(argv[1], "-")? fopen(argv[1], "rb") : stdin;
if (fp == 0) {
fprintf(stderr, "ERROR: fail to open the input file.\n");
return 1;
}
while (!feof(fp)) {
c = fgetc(fp);
if (isgraph(c) || c == '\t' || c == '\n' || c == ' ')
fputc(c, stdout);
}
if (c != '\n') fputc('\n', stdout);
fclose(fp);
return 0;
}
================================================
FILE: benchmarks/ext/genint.c
================================================
/* This program generates 5 million recurrent integers. Each distinct integer
* occurs 4 times in average.
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i, n = 500000; // by default, output 5 million integers
if (argc > 1) n = atoi(argv[1]);
srand(11);
for (i = 0; i < n; ++i)
printf("%u\n", (unsigned)((rand() % (n/4)) * 271828183u)); // 4 times in average
return 0;
}
================================================
FILE: benchmarks/ext/kbtree.h
================================================
/*-
* Copyright 1997-1999, 2001, John-Mark Gurney.
* 2008-2009, Attractive Chaos <attractor@live.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __AC_KBTREE_H
#define __AC_KBTREE_H
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
typedef struct {
int32_t is_internal:1, n:31;
} kbnode_t;
#define __KB_KEY(type, x) ((type*)((char*)x + 4))
#define __KB_PTR(btr, x) ((kbnode_t**)((char*)x + btr->off_ptr))
#define __KB_TREE_T(name) \
typedef struct { \
kbnode_t *root; \
int off_key, off_ptr, ilen, elen; \
int n, t; \
int n_keys, n_nodes; \
} kbtree_##name##_t;
#define __KB_INIT(name, key_t) \
kbtree_##name##_t *kb_init_##name(int size) \
{ \
kbtree_##name##_t *b; \
b = (kbtree_##name##_t*)calloc(1, sizeof(kbtree_##name##_t)); \
b->t = ((size - 4 - sizeof(void*)) / (sizeof(void*) + sizeof(key_t)) + 1) >> 1; \
if (b->t < 2) { \
free(b); return 0; \
} \
b->n = 2 * b->t - 1; \
b->off_ptr = 4 + b->n * sizeof(key_t); \
b->ilen = (4 + sizeof(void*) + b->n * (sizeof(void*) + sizeof(key_t)) + 3) >> 2 << 2; \
b->elen = (b->off_ptr + 3) >> 2 << 2; \
b->root = (kbnode_t*)calloc(1, b->ilen); \
++b->n_nodes; \
return b; \
}
#define __kb_destroy(b) do { \
int i, max = 8; \
kbnode_t *x, **top, **stack = 0; \
if (b) { \
top = stack = (kbnode_t**)calloc(max, sizeof(kbnode_t*)); \
*top++ = (b)->root; \
while (top != stack) { \
x = *--top; \
if (x->is_internal == 0) { free(x); continue; } \
for (i = 0; i <= x->n; ++i) \
if (__KB_PTR(b, x)[i]) { \
if (top - stack == max) { \
max <<= 1; \
stack = (kbnode_t**)realloc(stack, max * sizeof(kbnode_t*)); \
top = stack + (max>>1); \
} \
*top++ = __KB_PTR(b, x)[i]; \
} \
free(x); \
} \
} \
free(b); free(stack); \
} while (0)
#define __kb_get_first(key_t, b, ret) do { \
kbnode_t *__x = (b)->root; \
while (__KB_PTR(b, __x)[0] != 0) \
__x = __KB_PTR(b, __x)[0]; \
(ret) = __KB_KEY(key_t, __x)[0]; \
} while (0)
#define __KB_GET_AUX0(name, key_t, __cmp) \
static inline int __kb_get_aux_##name(const kbnode_t * __restrict x, const key_t * __restrict k, int *r) \
{ \
int tr, *rr, begin, end, n = x->n >> 1; \
if (x->n == 0) return -1; \
if (__cmp(*k, __KB_KEY(key_t, x)[n]) < 0) { \
begin = 0; end = n; \
} else { begin = n; end = x->n - 1; } \
rr = r? r : &tr; \
n = end; \
while (n >= begin && (*rr = __cmp(*k, __KB_KEY(key_t, x)[n])) < 0) --n; \
return n; \
}
#define __KB_GET_AUX1(name, key_t, __cmp) \
static inline int __kb_getp_aux_##name(const kbnode_t * __restrict x, const key_t * __restrict k, int *r) \
{ \
int tr, *rr, begin = 0, end = x->n; \
if (x->n == 0) return -1; \
rr = r? r : &tr; \
while (begin < end) { \
int mid = (begin + end) >> 1; \
if (__cmp(__KB_KEY(key_t, x)[mid], *k) < 0) begin = mid + 1; \
else end = mid; \
} \
if (begin == x->n) { *rr = 1; return x->n - 1; } \
if ((*rr = __cmp(*k, __KB_KEY(key_t, x)[begin])) < 0) --begin; \
return begin; \
}
#define __KB_GET(name, key_t) \
static key_t *kb_getp_##name(kbtree_##name##_t *b, const key_t * __restrict k) \
{ \
int i, r = 0; \
kbnode_t *x = b->root; \
while (x) { \
i = __kb_getp_aux_##name(x, k, &r); \
if (i >= 0 && r == 0) return &__KB_KEY(key_t, x)[i]; \
if (x->is_internal == 0) return 0; \
x = __KB_PTR(b, x)[i + 1]; \
} \
return 0; \
} \
static inline key_t *kb_get_##name(kbtree_##name##_t *b, const key_t k) \
{ \
return kb_getp_##name(b, &k); \
}
#define __KB_INTERVAL(name, key_t) \
static void kb_intervalp_##name(kbtree_##name##_t *b, const key_t * __restrict k, key_t **lower, key_t **upper) \
{ \
int i, r = 0; \
kbnode_t *x = b->root; \
*lower = *upper = 0; \
while (x) { \
i = __kb_getp_aux_##name(x, k, &r); \
if (i >= 0 && r == 0) { \
*lower = *upper = &__KB_KEY(key_t, x)[i]; \
return; \
} \
if (i >= 0) *lower = &__KB_KEY(key_t, x)[i]; \
if (i < x->n - 1) *upper = &__KB_KEY(key_t, x)[i + 1]; \
if (x->is_internal == 0) return; \
x = __KB_PTR(b, x)[i + 1]; \
} \
} \
static inline void kb_interval_##name(kbtree_##name##_t *b, const key_t k, key_t **lower, key_t **upper) \
{ \
kb_intervalp_##name(b, &k, lower, upper); \
}
#define __KB_PUT(name, key_t, __cmp) \
/* x must be an internal node */ \
static void __kb_split_##name(kbtree_##name##_t *b, kbnode_t *x, int i, kbnode_t *y) \
{ \
kbnode_t *z; \
z = (kbnode_t*)calloc(1, y->is_internal? b->ilen : b->elen); \
++b->n_nodes; \
z->is_internal = y->is_internal; \
z->n = b->t - 1; \
memcpy(__KB_KEY(key_t, z), __KB_KEY(key_t, y) + b->t, sizeof(key_t) * (b->t - 1)); \
if (y->is_internal) memcpy(__KB_PTR(b, z), __KB_PTR(b, y) + b->t, sizeof(void*) * b->t); \
y->n = b->t - 1; \
memmove(__KB_PTR(b, x) + i + 2, __KB_PTR(b, x) + i + 1, sizeof(void*) * (x->n - i)); \
__KB_PTR(b, x)[i + 1] = z; \
memmove(__KB_KEY(key_t, x) + i + 1, __KB_KEY(key_t, x) + i, sizeof(key_t) * (x->n - i)); \
__KB_KEY(key_t, x)[i] = __KB_KEY(key_t, y)[b->t - 1]; \
++x->n; \
} \
static void __kb_putp_aux_##name(kbtree_##name##_t *b, kbnode_t *x, const key_t * __restrict k) \
{ \
int i = x->n - 1; \
if (x->is_internal == 0) { \
i = __kb_getp_aux_##name(x, k, 0); \
if (i != x->n - 1) \
memmove(__KB_KEY(key_t, x) + i + 2, __KB_KEY(key_t, x) + i + 1, (x->n - i - 1) * sizeof(key_t)); \
__KB_KEY(key_t, x)[i + 1] = *k; \
++x->n; \
} else { \
i = __kb_getp_aux_##name(x, k, 0) + 1; \
if (__KB_PTR(b, x)[i]->n == 2 * b->t - 1) { \
__kb_split_##name(b, x, i, __KB_PTR(b, x)[i]); \
if (__cmp(*k, __KB_KEY(key_t, x)[i]) > 0) ++i; \
} \
__kb_putp_aux_##name(b, __KB_PTR(b, x)[i], k); \
} \
} \
static void kb_putp_##name(kbtree_##name##_t *b, const key_t * __restrict k) \
{ \
kbnode_t *r, *s; \
++b->n_keys; \
r = b->root; \
if (r->n == 2 * b->t - 1) { \
++b->n_nodes; \
s = (kbnode_t*)calloc(1, b->ilen); \
b->root = s; s->is_internal = 1; s->n = 0; \
__KB_PTR(b, s)[0] = r; \
__kb_split_##name(b, s, 0, r); \
r = s; \
} \
__kb_putp_aux_##name(b, r, k); \
} \
static inline void kb_put_##name(kbtree_##name##_t *b, const key_t k) \
{ \
kb_putp_##name(b, &k); \
}
#define __KB_DEL(name, key_t) \
static key_t __kb_delp_aux_##name(kbtree_##name##_t *b, kbnode_t *x, const key_t * __restrict k, int s) \
{ \
int yn, zn, i, r = 0; \
kbnode_t *xp, *y, *z; \
key_t kp; \
if (x == 0) return *k; \
if (s) { /* s can only be 0, 1 or 2 */ \
r = x->is_internal == 0? 0 : s == 1? 1 : -1; \
i = s == 1? x->n - 1 : -1; \
} else i = __kb_getp_aux_##name(x, k, &r); \
if (x->is_internal == 0) { \
if (s == 2) ++i; \
kp = __KB_KEY(key_t, x)[i]; \
memmove(__KB_KEY(key_t, x) + i, __KB_KEY(key_t, x) + i + 1, (x->n - i - 1) * sizeof(key_t)); \
--x->n; \
return kp; \
} \
if (r == 0) { \
if ((yn = __KB_PTR(b, x)[i]->n) >= b->t) { \
xp = __KB_PTR(b, x)[i]; \
kp = __KB_KEY(key_t, x)[i]; \
__KB_KEY(key_t, x)[i] = __kb_delp_aux_##name(b, xp, 0, 1); \
return kp; \
} else if ((zn = __KB_PTR(b, x)[i + 1]->n) >= b->t) { \
xp = __KB_PTR(b, x)[i + 1]; \
kp = __KB_KEY(key_t, x)[i]; \
__KB_KEY(key_t, x)[i] = __kb_delp_aux_##name(b, xp, 0, 2); \
return kp; \
} else if (yn == b->t - 1 && zn == b->t - 1) { \
y = __KB_PTR(b, x)[i]; z = __KB_PTR(b, x)[i + 1]; \
__KB_KEY(key_t, y)[y->n++] = *k; \
memmove(__KB_KEY(key_t, y) + y->n, __KB_KEY(key_t, z), z->n * sizeof(key_t)); \
if (y->is_internal) memmove(__KB_PTR(b, y) + y->n, __KB_PTR(b, z), (z->n + 1) * sizeof(void*)); \
y->n += z->n; \
memmove(__KB_KEY(key_t, x) + i, __KB_KEY(key_t, x) + i + 1, (x->n - i - 1) * sizeof(key_t)); \
memmove(__KB_PTR(b, x) + i + 1, __KB_PTR(b, x) + i + 2, (x->n - i - 1) * sizeof(void*)); \
--x->n; \
free(z); \
return __kb_delp_aux_##name(b, y, k, s); \
} \
} \
++i; \
if ((xp = __KB_PTR(b, x)[i])->n == b->t - 1) { \
if (i > 0 && (y = __KB_PTR(b, x)[i - 1])->n >= b->t) { \
memmove(__KB_KEY(key_t, xp) + 1, __KB_KEY(key_t, xp), xp->n * sizeof(key_t)); \
if (xp->is_internal) memmove(__KB_PTR(b, xp) + 1, __KB_PTR(b, xp), (xp->n + 1) * sizeof(void*)); \
__KB_KEY(key_t, xp)[0] = __KB_KEY(key_t, x)[i - 1]; \
__KB_KEY(key_t, x)[i - 1] = __KB_KEY(key_t, y)[y->n - 1]; \
if (xp->is_internal) __KB_PTR(b, xp)[0] = __KB_PTR(b, y)[y->n]; \
--y->n; ++xp->n; \
} else if (i < x->n && (y = __KB_PTR(b, x)[i + 1])->n >= b->t) { \
__KB_KEY(key_t, xp)[xp->n++] = __KB_KEY(key_t, x)[i]; \
__KB_KEY(key_t, x)[i] = __KB_KEY(key_t, y)[0]; \
if (xp->is_internal) __KB_PTR(b, xp)[xp->n] = __KB_PTR(b, y)[0]; \
--y->n; \
memmove(__KB_KEY(key_t, y), __KB_KEY(key_t, y) + 1, y->n * sizeof(key_t)); \
if (y->is_internal) memmove(__KB_PTR(b, y), __KB_PTR(b, y) + 1, (y->n + 1) * sizeof(void*)); \
} else if (i > 0 && (y = __KB_PTR(b, x)[i - 1])->n == b->t - 1) { \
__KB_KEY(key_t, y)[y->n++] = __KB_KEY(key_t, x)[i - 1]; \
memmove(__KB_KEY(key_t, y) + y->n, __KB_KEY(key_t, xp), xp->n * sizeof(key_t)); \
if (y->is_internal) memmove(__KB_PTR(b, y) + y->n, __KB_PTR(b, xp), (xp->n + 1) * sizeof(void*)); \
y->n += xp->n; \
memmove(__KB_KEY(key_t, x) + i - 1, __KB_KEY(key_t, x) + i, (x->n - i) * sizeof(key_t)); \
memmove(__KB_PTR(b, x) + i, __KB_PTR(b, x) + i + 1, (x->n - i) * sizeof(void*)); \
--x->n; \
free(xp); \
xp = y; \
} else if (i < x->n && (y = __KB_PTR(b, x)[i +
gitextract_qcet_0lf/
├── .gitattributes
├── .gitignore
├── LICENSE.md
├── Makefile
├── README.md
├── TODO.md
├── benchmarks/
│ ├── Dict/
│ │ ├── dict_c.c
│ │ ├── dict_cello.c
│ │ ├── dict_cpp.cpp
│ │ ├── dict_cs.cs
│ │ ├── dict_d.d
│ │ ├── dict_go.go
│ │ ├── dict_java.java
│ │ ├── dict_javascript.js
│ │ ├── dict_lua.lua
│ │ ├── dict_perl.pl
│ │ ├── dict_python.py
│ │ └── dict_ruby.rb
│ ├── GC/
│ │ ├── gc_c.c
│ │ ├── gc_cello.c
│ │ ├── gc_cpp.cpp
│ │ ├── gc_java.java
│ │ ├── gc_javascript.js
│ │ ├── gc_lua.lua
│ │ ├── gc_python.py
│ │ └── gc_ruby.rb
│ ├── List/
│ │ ├── list_c.c
│ │ ├── list_cello.c
│ │ ├── list_cpp.cpp
│ │ ├── list_java.java
│ │ ├── list_javascript.js
│ │ ├── list_lua.lua
│ │ ├── list_python.py
│ │ └── list_ruby.rb
│ ├── Map/
│ │ ├── dict.lua
│ │ ├── map_c.c
│ │ ├── map_cello.c
│ │ ├── map_cpp.cpp
│ │ ├── map_cs.cs
│ │ ├── map_d.d
│ │ ├── map_go.go
│ │ ├── map_java.java
│ │ ├── map_javascript.js
│ │ ├── map_lua.lua
│ │ ├── map_perl.pl
│ │ ├── map_python.py
│ │ ├── map_ruby.rb
│ │ ├── rb.lua
│ │ └── redblack.lua
│ ├── Matmul/
│ │ ├── matmul_c.c
│ │ ├── matmul_cello.c
│ │ ├── matmul_cpp.cpp
│ │ ├── matmul_cs.cs
│ │ ├── matmul_d.d
│ │ ├── matmul_dart.dart
│ │ ├── matmul_go.go
│ │ ├── matmul_java.java
│ │ ├── matmul_javascript.js
│ │ ├── matmul_lua.lua
│ │ ├── matmul_perl.pl
│ │ ├── matmul_python.py
│ │ ├── matmul_r.R
│ │ └── matmul_ruby.rb
│ ├── Nbodies/
│ │ ├── nbodies_c.c
│ │ ├── nbodies_cello.c
│ │ ├── nbodies_cpp.cpp
│ │ ├── nbodies_java.java
│ │ ├── nbodies_javascript.js
│ │ ├── nbodies_lua.lua
│ │ ├── nbodies_python.py
│ │ └── nbodies_ruby.rb
│ ├── Sudoku/
│ │ ├── sudoku_c.c
│ │ ├── sudoku_cello.c
│ │ ├── sudoku_cpp.cpp
│ │ ├── sudoku_cs.cs
│ │ ├── sudoku_d.d
│ │ ├── sudoku_dart.dart
│ │ ├── sudoku_go.go
│ │ ├── sudoku_java.java
│ │ ├── sudoku_javascript.js
│ │ ├── sudoku_lua.lua
│ │ ├── sudoku_perl.pl
│ │ ├── sudoku_python.py
│ │ └── sudoku_ruby.rb
│ ├── benchmark
│ ├── benchmark.sh
│ ├── ext/
│ │ ├── cleantxt.c
│ │ ├── genint.c
│ │ ├── kbtree.h
│ │ ├── khash.h
│ │ ├── kvec.h
│ │ ├── regexp9.c
│ │ ├── regexp9.h
│ │ ├── sudoku
│ │ └── sudoku.txt
│ └── graphs.py
├── examples/
│ ├── cello_world.c
│ ├── help.c
│ ├── iteration.c
│ ├── newtype.c
│ ├── object.c
│ ├── ranges.c
│ ├── table.c
│ └── threads.c
├── include/
│ └── Cello.h
├── src/
│ ├── Alloc.c
│ ├── Array.c
│ ├── Assign.c
│ ├── Cmp.c
│ ├── Concat.c
│ ├── Doc.c
│ ├── Exception.c
│ ├── File.c
│ ├── Function.c
│ ├── GC.c
│ ├── Get.c
│ ├── Hash.c
│ ├── Iter.c
│ ├── Len.c
│ ├── List.c
│ ├── Num.c
│ ├── Pointer.c
│ ├── Push.c
│ ├── Resize.c
│ ├── Show.c
│ ├── Start.c
│ ├── String.c
│ ├── Table.c
│ ├── Thread.c
│ ├── Tree.c
│ ├── Tuple.c
│ └── Type.c
└── tests/
├── ptest.c
├── ptest.h
└── test.c
SYMBOL INDEX (1165 symbols across 98 files)
FILE: benchmarks/Dict/dict_c.c
function main (line 8) | int main(int argc, char *argv[])
FILE: benchmarks/Dict/dict_cello.c
function main (line 10) | int main(int argc, char *argv[]) {
FILE: benchmarks/Dict/dict_cpp.cpp
type eqstr (line 9) | struct eqstr {
type std (line 15) | namespace std {
type hash<const char *> (line 17) | struct hash<const char *> : public std::unary_function<const char *, s...
function main (line 32) | int main(int argc, char *argv[])
FILE: benchmarks/Dict/dict_cs.cs
class dict_v1 (line 4) | class dict_v1 {
method Main (line 5) | static void Main() {
FILE: benchmarks/Dict/dict_go.go
function main (line 10) | func main() {
FILE: benchmarks/Dict/dict_java.java
class dict_java (line 4) | class dict_java {
method main (line 5) | public static void main(String[] args) {
FILE: benchmarks/Dict/dict_javascript.js
function processLine (line 4) | function processLine (l) {
FILE: benchmarks/Dict/dict_python.py
function count_duplicates (line 3) | def count_duplicates(lines):
FILE: benchmarks/GC/gc_c.c
function create_objects (line 3) | static void create_objects(int depth) {
function main (line 34) | int main(int argc, char** argv) {
FILE: benchmarks/GC/gc_cello.c
function create_objects (line 3) | static void create_objects(int depth) {
function main (line 34) | int main(int argc, char** argv) {
FILE: benchmarks/GC/gc_cpp.cpp
class Int (line 3) | class Int {
method Int (line 6) | Int() : i(0) {}
function create_objects (line 9) | static void create_objects(int depth) {
function main (line 40) | int main(int argc, char** argv) {
FILE: benchmarks/GC/gc_java.java
class gc_java (line 1) | public final class gc_java {
class Int (line 3) | final public static class Int {
method Int (line 5) | Int(int x) {
method create_objects (line 10) | public static void create_objects(int depth) {
method main (line 41) | public static void main(String[] args) {
FILE: benchmarks/GC/gc_javascript.js
function Int (line 2) | function Int() {
function create_objects (line 6) | function create_objects(depth) {
FILE: benchmarks/GC/gc_python.py
class Int (line 2) | class Int:
function create_objects (line 5) | def create_objects(depth):
FILE: benchmarks/GC/gc_ruby.rb
class Int (line 2) | class Int
function create_objects (line 5) | def create_objects(depth)
FILE: benchmarks/List/list_c.c
function main (line 5) | int main(int argc, char** argv) {
FILE: benchmarks/List/list_cello.c
function main (line 3) | int main(int argc, char** argv) {
FILE: benchmarks/List/list_cpp.cpp
function main (line 4) | int main(int argc, char** argv) {
FILE: benchmarks/List/list_java.java
class list_java (line 5) | class list_java {
method main (line 6) | public static void main(String[] args) {
FILE: benchmarks/Map/map_c.c
type elem_t (line 4) | typedef struct {
function main (line 15) | int main(int argc, char *argv[])
FILE: benchmarks/Map/map_cello.c
function main (line 10) | int main(int argc, char *argv[]) {
FILE: benchmarks/Map/map_cpp.cpp
type eqstr (line 9) | struct eqstr {
function main (line 20) | int main(int argc, char *argv[])
FILE: benchmarks/Map/map_cs.cs
class dict_v1 (line 4) | class dict_v1 {
method Main (line 5) | static void Main() {
FILE: benchmarks/Map/map_go.go
function main (line 10) | func main() {
FILE: benchmarks/Map/map_java.java
class map_java (line 4) | class map_java {
method main (line 5) | public static void main(String[] args) {
FILE: benchmarks/Map/map_javascript.js
function processLine (line 7) | function processLine (l) {
FILE: benchmarks/Map/map_python.py
function count_duplicates (line 4) | def count_duplicates(lines):
FILE: benchmarks/Matmul/matmul_c.c
function mm_destroy (line 15) | void mm_destroy(int n, double **m)
function main (line 52) | int main(int argc, char *argv[])
FILE: benchmarks/Matmul/matmul_cello.c
type Matrix (line 3) | struct Matrix {
function Matrix_New (line 8) | static void Matrix_New(var self, var args) {
function Matrix_Del (line 17) | static void Matrix_Del(var self) {
type Matrix (line 25) | struct Matrix
type Matrix (line 26) | struct Matrix
function var (line 36) | static var Matrix_Mul(var m0, var m1) {
function main (line 60) | int main(int argc, char *argv[]) {
FILE: benchmarks/Matmul/matmul_cpp.cpp
class Matrix (line 3) | class Matrix {
function Matrix (line 27) | static Matrix* Matrix_Gen(int n) {
function Matrix (line 38) | static Matrix* Matrix_Mul(Matrix* m0, Matrix* m1) {
function main (line 62) | int main(int argc, char *argv[]) {
FILE: benchmarks/Matmul/matmul_cs.cs
class matmul_v1 (line 8) | class matmul_v1 {
method matgen (line 9) | public double[,] matgen(int n) {
method matmul (line 17) | public double[,] matmul(double[,] a, double[,] b) {
method Main (line 33) | public static void Main(String[] args) {
FILE: benchmarks/Matmul/matmul_dart.dart
function mat_transpose (line 3) | mat_transpose(a)
function mat_mul (line 14) | mat_mul(a, b)
function inner_loop (line 16) | inner_loop(t, n, ai, c)
function mat_gen (line 35) | mat_gen(int n)
function main (line 47) | main()
FILE: benchmarks/Matmul/matmul_go.go
function matgen (line 9) | func matgen(n int) [][]float64 {
function matmul (line 21) | func matmul(a [][]float64, b [][]float64) [][]float64 {
function main (line 46) | func main() {
FILE: benchmarks/Matmul/matmul_java.java
class matmul_java (line 3) | class matmul_java {
method matgen (line 4) | public double[][] matgen(int n) {
method matmul (line 12) | public double[][] matmul(double[][] a, double[][] b) {
method main (line 28) | public static void main(String[] args) {
FILE: benchmarks/Matmul/matmul_javascript.js
function matgen (line 30) | function matgen(n) {
FILE: benchmarks/Matmul/matmul_python.py
function matmul (line 7) | def matmul(a, b): # FIXME: no error checking
function main (line 20) | def main():
FILE: benchmarks/Matmul/matmul_ruby.rb
function matmul (line 6) | def matmul(a, b)
function matgen (line 32) | def matgen(n)
FILE: benchmarks/Nbodies/nbodies_c.c
type Body (line 10) | struct Body {
function Body_Offset_Momentum (line 16) | static void Body_Offset_Momentum(struct Body* b, double px, double py, d...
function Bodies_Advance (line 22) | static void Bodies_Advance(struct Body* bodies, size_t nbodies, double d...
function Bodies_Energy (line 58) | static double Bodies_Energy(struct Body* bodies, size_t nbodies) {
function main (line 91) | int main(int argc, char** argv) {
FILE: benchmarks/Nbodies/nbodies_cello.c
type Body (line 6) | struct Body {
function Body_Offset_Momentum (line 12) | static void Body_Offset_Momentum(struct Body* self, double px, double py...
function Bodies_Advance (line 20) | static void Bodies_Advance(var bodies, double dt) {
function Bodies_Energy (line 58) | static double Bodies_Energy(var bodies) {
function main (line 92) | int main(int argc, char** argv) {
FILE: benchmarks/Nbodies/nbodies_cpp.cpp
class Body (line 10) | class Body {
method Body (line 14) | Body(double x, double y, double z,
method Offset_Momentum (line 22) | void Offset_Momentum(double px, double py, double pz) {
function Bodies_Advance (line 30) | static void Bodies_Advance(std::vector<Body*> bodies, double dt) {
function Bodies_Energy (line 65) | static double Bodies_Energy(std::vector<Body*> bodies) {
function main (line 98) | int main(int argc, char** argv) {
FILE: benchmarks/Nbodies/nbodies_java.java
class nbodies_java (line 1) | public final class nbodies_java {
method main (line 2) | public static void main(String[] args) {
class NBodySystem (line 11) | final class NBodySystem {
method NBodySystem (line 14) | public NBodySystem(){
method advance (line 34) | public void advance(double dt) {
method energy (line 64) | public double energy(){
class Body (line 90) | final class Body {
method Body (line 97) | public Body(){}
method jupiter (line 99) | static Body jupiter(){
method saturn (line 111) | static Body saturn(){
method uranus (line 123) | static Body uranus(){
method neptune (line 135) | static Body neptune(){
method sun (line 147) | static Body sun(){
method offsetMomentum (line 153) | Body offsetMomentum(double px, double py, double pz){
FILE: benchmarks/Nbodies/nbodies_javascript.js
function body_offset_momentum (line 47) | function body_offset_momentum(b, px, py, pz) {
function bodies_new (line 54) | function bodies_new() {
function bodies_advance (line 74) | function bodies_advance(bodies, dt) {
function bodies_energy (line 111) | function bodies_energy(bodies) {
FILE: benchmarks/Nbodies/nbodies_python.py
class Body (line 12) | class Body:
method __init__ (line 14) | def __init__(self, x, y, z, vx, vy, vz, mass):
function body_offset_momentum (line 72) | def body_offset_momentum(b, px, py, pz):
function bodies_new (line 78) | def bodies_new():
function bodies_advance (line 98) | def bodies_advance(bodies, dt):
function bodies_energy (line 130) | def bodies_energy(bodies):
FILE: benchmarks/Nbodies/nbodies_ruby.rb
class Planet (line 4) | class Planet
method initialize (line 7) | def initialize(x, y, z, vx, vy, vz, mass)
method move_from_i (line 13) | def move_from_i(bodies, nbodies, dt, i)
function energy (line 39) | def energy(bodies)
function offset_momentum (line 58) | def offset_momentum(bodies)
FILE: benchmarks/Sudoku/sudoku_c.c
type sdaux_t (line 80) | typedef struct {
function sdaux_t (line 86) | sdaux_t *sd_genmat()
function sd_update (line 107) | static inline int sd_update(const sdaux_t *aux, int8_t sr[729], uint8_t ...
function sd_solve (line 133) | int sd_solve(const sdaux_t *aux, const char *_s)
function main (line 179) | int main()
FILE: benchmarks/Sudoku/sudoku_cello.c
type Sudoku (line 3) | struct Sudoku {
function Sudoku_New (line 8) | static void Sudoku_New(var self, var args) {
function Sudoku_Update (line 30) | static int Sudoku_Update(
function Sudoku_Solve (line 58) | static int Sudoku_Solve(struct Sudoku* aux, const char *_s) {
function main (line 103) | int main(int argc, char** argv) {
FILE: benchmarks/Sudoku/sudoku_cpp.cpp
class sdaux_t (line 80) | class sdaux_t {
function main (line 181) | int main()
FILE: benchmarks/Sudoku/sudoku_cs.cs
class sudoku_v1 (line 3) | class sudoku_v1 {
method genmat (line 5) | public void genmat() {
method sd_update (line 25) | private int sd_update(int[] sr, int[] sc, int r, int v) {
method solve (line 50) | public int solve(String _s) {
method Main (line 98) | public static void Main(String[] args) {
FILE: benchmarks/Sudoku/sudoku_dart.dart
class Sudoku (line 5) | class Sudoku {
function main (line 98) | main()
FILE: benchmarks/Sudoku/sudoku_go.go
type sdaux_t (line 9) | type sdaux_t struct
function sd_genmat (line 14) | func sd_genmat() *sdaux_t {
function sd_update_forward (line 42) | func sd_update_forward(aux *sdaux_t, sr []int8, sc []uint8, r uint16) int {
function sd_update_revert (line 66) | func sd_update_revert(aux *sdaux_t, sr []int8, sc []uint8, r uint16) {
function sd_solve (line 84) | func sd_solve(aux *sdaux_t, _s []byte) int {
function main (line 161) | func main() {
FILE: benchmarks/Sudoku/sudoku_java.java
class sudoku_java (line 3) | class sudoku_java {
method genmat (line 5) | public void genmat() {
method sd_update (line 25) | private int sd_update(int[] sr, int[] sc, int r, int v) {
method solve (line 51) | public int solve(String _s) {
method main (line 99) | public static void main(String[] args) throws Exception {
FILE: benchmarks/Sudoku/sudoku_javascript.js
function Sudoku (line 1) | function Sudoku() {
function processLine (line 90) | function processLine (l) {
FILE: benchmarks/Sudoku/sudoku_python.py
function sd_genmat (line 8) | def sd_genmat():
function sd_update (line 16) | def sd_update(R, C, sr, sc, r, v):
function sd_solve (line 37) | def sd_solve(R, C, s):
FILE: benchmarks/Sudoku/sudoku_ruby.rb
function sd_genmat (line 1) | def sd_genmat()
function sd_update (line 21) | def sd_update(mr, mc, sr, sc, r, v)
function sd_solve (line 56) | def sd_solve(mr, mc, s)
FILE: benchmarks/ext/cleantxt.c
function main (line 5) | int main(int argc, char *argv[])
FILE: benchmarks/ext/genint.c
function main (line 7) | int main(int argc, char *argv[])
FILE: benchmarks/ext/kbtree.h
type kbnode_t (line 35) | typedef struct {
type __kbstack_t (line 327) | typedef struct {
FILE: benchmarks/ext/khash.h
type khint32_t (line 106) | typedef unsigned int khint32_t;
type khint32_t (line 108) | typedef unsigned long khint32_t;
type khint64_t (line 112) | typedef unsigned long khint64_t;
type khint64_t (line 114) | typedef unsigned long long khint64_t;
type khint32_t (line 121) | typedef khint32_t khint_t;
type khint_t (line 122) | typedef khint_t khiter_t;
function khint_t (line 336) | static inline khint_t __ac_X31_hash_string(const char *s)
FILE: benchmarks/ext/regexp9.c
function chartorune (line 74) | int
function Rune (line 130) | Rune*
function _renewmatch (line 182) | static void
function Relist (line 203) | static Relist*
function Relist (line 235) | static Relist*
function Relist (line 261) | static Relist*
type Node (line 297) | typedef
function rcerror (line 332) | static void
function Reinst (line 340) | static Reinst*
function operand (line 349) | static void
function operator (line 367) | static void
function regerr2 (line 387) | static void
function cant (line 399) | static void
function pushand (line 408) | static void
function pushator (line 418) | static void
function Node (line 427) | static Node*
function popator (line 440) | static int
function evaluntil (line 449) | static void
function Reprog (line 514) | static Reprog*
function dumpstack (line 566) | static void
function dump (line 579) | static void
function Reclass (line 607) | static Reclass*
function nextc (line 615) | static int
function lex (line 632) | static int
function bldcclass (line 671) | static int
function Reprog (line 757) | static Reprog*
function Reprog (line 825) | extern Reprog*
function Reprog (line 831) | extern Reprog*
function Reprog (line 837) | extern Reprog*
function regexec1 (line 852) | static int
function regexec2 (line 998) | static int
function regexec9 (line 1029) | extern int
function regsub9 (line 1079) | extern void
function regerror9 (line 1143) | void
function rregexec1 (line 1164) | static int
function rregexec2 (line 1304) | static int
function rregexec9 (line 1323) | extern int
function rregsub9 (line 1373) | extern void
FILE: benchmarks/ext/regexp9.h
type Rune (line 8) | typedef unsigned short Rune;
type Resub (line 10) | typedef struct Resub Resub;
type Reclass (line 11) | typedef struct Reclass Reclass;
type Reinst (line 12) | typedef struct Reinst Reinst;
type Reprog (line 13) | typedef struct Reprog Reprog;
type Resub (line 38) | struct Resub{
type Reclass (line 54) | struct Reclass{
type Reinst (line 62) | struct Reinst{
type Reprog (line 79) | struct Reprog{
type uchar (line 111) | typedef unsigned char uchar;
type Resublist (line 115) | typedef struct Resublist Resublist;
type Resublist (line 116) | struct Resublist
type Relist (line 158) | typedef struct Relist Relist;
type Relist (line 159) | struct Relist
type Reljunk (line 164) | typedef struct Reljunk Reljunk;
type Reljunk (line 165) | struct Reljunk
FILE: examples/cello_world.c
function main (line 3) | int main(int argc, char** argv) {
FILE: examples/help.c
function main (line 3) | int main(int argc, char** argv) {
FILE: examples/iteration.c
function main (line 3) | int main(int argc, char** argv) {
FILE: examples/newtype.c
type ExampleType (line 7) | struct ExampleType {
function ExampleType_New (line 12) | static void ExampleType_New(var self, var args) {
function ExampleType_Cmp (line 18) | static int ExampleType_Cmp(var self, var obj) {
function main (line 24) | int main(int argc, char** argv) {
FILE: examples/object.c
type Point (line 4) | struct Point {
function main (line 11) | int main(int argc, char** argv) {
FILE: examples/ranges.c
function main (line 3) | int main(int argc, char** argv) {
FILE: examples/table.c
function main (line 3) | int main(int argc, char** argv) {
FILE: examples/threads.c
function var (line 4) | var say_hello(var args) {
function main (line 11) | int main(int argc, char** argv) {
FILE: include/Cello.h
type Header (line 228) | struct Header {
type Type (line 238) | struct Type {
type Ref (line 244) | struct Ref {
type Box (line 248) | struct Box {
type Int (line 252) | struct Int {
type Float (line 256) | struct Float {
type String (line 260) | struct String {
type Tuple (line 264) | struct Tuple {
type Range (line 268) | struct Range {
type Slice (line 275) | struct Slice {
type Zip (line 280) | struct Zip {
type Filter (line 285) | struct Filter {
type Map (line 290) | struct Map {
type File (line 296) | struct File {
type Process (line 300) | struct Process {
type Function (line 304) | struct Function {
type Example (line 343) | struct Example {
type Method (line 348) | struct Method {
type Doc (line 354) | struct Doc {
type Help (line 363) | struct Help {
type Cast (line 367) | struct Cast {
type Size (line 371) | struct Size {
type Alloc (line 375) | struct Alloc {
type New (line 380) | struct New {
type Copy (line 385) | struct Copy {
type Assign (line 389) | struct Assign {
type Swap (line 393) | struct Swap {
type Cmp (line 397) | struct Cmp {
type Hash (line 401) | struct Hash {
type Len (line 405) | struct Len {
type Push (line 409) | struct Push {
type Concat (line 416) | struct Concat {
type Get (line 421) | struct Get {
type Iter (line 430) | struct Iter {
type Sort (line 438) | struct Sort {
type Resize (line 442) | struct Resize {
type C_Str (line 446) | struct C_Str {
type C_Int (line 450) | struct C_Int {
type C_Float (line 454) | struct C_Float {
type Stream (line 458) | struct Stream {
type Pointer (line 469) | struct Pointer {
type Call (line 474) | struct Call {
type Format (line 478) | struct Format {
type Show (line 483) | struct Show {
type Current (line 488) | struct Current {
type Start (line 492) | struct Start {
type Lock (line 499) | struct Lock {
type Mark (line 505) | struct Mark {
type Header (line 546) | struct Header
FILE: src/Alloc.c
type Header (line 3) | struct Header
type Header (line 4) | struct Header
type Header (line 4) | struct Header
function var (line 7) | var header_init(var head, var type, int alloc) {
type Example (line 56) | struct Example
type Example (line 58) | struct Example
type Method (line 77) | struct Method
type Method (line 79) | struct Method
function var (line 127) | static var alloc_by(var type, int method) {
function var (line 162) | var alloc(var type) { return alloc_by(type, ALLOC_STANDARD); }
function var (line 163) | var alloc_raw(var type) { return alloc_by(type, ALLOC_RAW); }
function var (line 164) | var alloc_root(var type) { return alloc_by(type, ALLOC_ROOT); }
function dealloc (line 166) | void dealloc(var self) {
function dealloc_raw (line 209) | void dealloc_raw(var self) { dealloc(self); }
function dealloc_root (line 210) | void dealloc_root(var self) { dealloc(self); }
type Example (line 254) | struct Example
type Example (line 256) | struct Example
type Method (line 273) | struct Method
type Method (line 275) | struct Method
function var (line 317) | var construct_with(var self, var args) {
function var (line 327) | var destruct(var self) {
function var (line 335) | var new_with(var type, var args) {
function var (line 339) | var new_raw_with(var type, var args) {
function var (line 343) | var new_root_with(var type, var args) {
function del_by (line 347) | static void del_by(var self, int method) {
function del (line 364) | void del(var self) { del_by(self, ALLOC_STANDARD); }
function del_raw (line 365) | void del_raw(var self) { del_by(self, ALLOC_RAW); }
function del_root (line 366) | void del_root(var self) { del_by(self, ALLOC_ROOT); }
type Example (line 402) | struct Example
type Example (line 404) | struct Example
type Method (line 419) | struct Method
type Method (line 421) | struct Method
function var (line 437) | var copy(var self) {
FILE: src/Array.c
type Example (line 30) | struct Example
type Example (line 32) | struct Example
type Array (line 80) | struct Array {
function Array_Step (line 88) | static size_t Array_Step(struct Array* a) {
function var (line 92) | static var Array_Item(struct Array* a, size_t i) {
function Array_Alloc (line 96) | static void Array_Alloc(struct Array* a, size_t i) {
function Array_Size_Round (line 102) | static size_t Array_Size_Round(size_t s) {
function Array_New (line 106) | static void Array_New(var self, var args) {
function Array_Del (line 134) | static void Array_Del(var self) {
function Array_Clear (line 146) | static void Array_Clear(var self) {
function Array_Assign (line 161) | static void Array_Assign(var self, var obj) {
function Array_Reserve_More (line 205) | static void Array_Reserve_More(struct Array* a) {
function Array_Concat (line 219) | static void Array_Concat(var self, var obj) {
function Array_Cmp (line 240) | static int Array_Cmp(var self, var obj) {
function Array_Hash (line 259) | static uint64_t Array_Hash(var self) {
function Array_Len (line 270) | static size_t Array_Len(var self) {
function Array_Mem (line 275) | static bool Array_Mem(var self, var obj) {
function Array_Reserve_Less (line 285) | static void Array_Reserve_Less(struct Array* a) {
function Array_Pop_At (line 292) | static void Array_Pop_At(var self, var key) {
function Array_Rem (line 316) | static void Array_Rem(var self, var obj) {
function Array_Push (line 327) | static void Array_Push(var self, var obj) {
function Array_Push_At (line 335) | static void Array_Push_At(var self, var obj, var key) {
function Array_Pop (line 359) | static void Array_Pop(var self) {
function var (line 376) | static var Array_Get(var self, var key) {
function Array_Set (line 392) | static void Array_Set(var self, var key, var val) {
function var (line 409) | static var Array_Iter_Init(var self) {
function var (line 415) | static var Array_Iter_Next(var self, var curr) {
function var (line 424) | static var Array_Iter_Last(var self) {
function var (line 430) | static var Array_Iter_Prev(var self, var curr) {
function var (line 439) | static var Array_Iter_Type(var self) {
function Array_Sort_Partition (line 444) | static size_t Array_Sort_Partition(
function Array_Sort_Part (line 463) | static void Array_Sort_Part(struct Array* a, int64_t l, int64_t r, bool(...
function Array_Sort_By (line 471) | static void Array_Sort_By(var self, bool(*f)(var,var)) {
function Array_Show (line 475) | static int Array_Show(var self, var output, int pos) {
function Array_Resize (line 485) | static void Array_Resize(var self, size_t n) {
function Array_Mark (line 509) | static void Array_Mark(var self, var gc, void(*f)(var,void*)) {
FILE: src/Assign.c
type Example (line 35) | struct Example
type Example (line 37) | struct Example
type Method (line 56) | struct Method
type Method (line 58) | struct Method
function var (line 75) | var assign(var self, var obj) {
type Example (line 120) | struct Example
type Example (line 122) | struct Example
type Method (line 138) | struct Method
type Method (line 140) | struct Method
function memswap (line 156) | static void memswap(void* p0, void* p1, size_t s) {
function swap (line 165) | void swap(var self, var obj) {
FILE: src/Cmp.c
type Example (line 42) | struct Example
type Example (line 44) | struct Example
type Method (line 75) | struct Method
type Method (line 77) | struct Method
function cmp (line 120) | int cmp(var self, var obj) {
function eq (line 134) | bool eq(var self, var obj) { return cmp(self, obj) is 0; }
function neq (line 135) | bool neq(var self, var obj) { return not eq(self, obj); }
function gt (line 136) | bool gt(var self, var obj) { return cmp(self, obj) > 0; }
function lt (line 137) | bool lt(var self, var obj) { return cmp(self, obj) < 0; }
function ge (line 138) | bool ge(var self, var obj) { return not lt(self, obj); }
function le (line 139) | bool le(var self, var obj) { return not gt(self, obj); }
type Example (line 163) | struct Example
type Example (line 165) | struct Example
type Method (line 180) | struct Method
type Method (line 182) | struct Method
function sort (line 202) | void sort(var self) {
function sort_by (line 206) | void sort_by(var self, bool(*f)(var,var)) {
FILE: src/Concat.c
type Example (line 26) | struct Example
type Example (line 28) | struct Example
type Method (line 47) | struct Method
type Method (line 49) | struct Method
function append (line 69) | void append(var self, var obj) {
function concat (line 73) | void concat(var self, var obj) {
FILE: src/Doc.c
type Method (line 45) | struct Method
type Method (line 47) | struct Method
type Example (line 70) | struct Example
type Example (line 72) | struct Example
type Doc (line 90) | struct Doc
type Method (line 130) | struct Method
type Method (line 132) | struct Method
type Example (line 145) | struct Example
type Example (line 147) | struct Example
function help_to (line 163) | int help_to(var out, int pos, var self) {
function help (line 167) | void help(var self) {
FILE: src/Exception.c
type Exception (line 28) | struct Exception {
type Method (line 65) | struct Method
type Method (line 67) | struct Method
type Example (line 100) | struct Example
type Example (line 102) | struct Example
function Exception_New (line 121) | static void Exception_New(var self, var args) {
function Exception_Del (line 131) | static void Exception_Del(var self) {
function Exception_Assign (line 137) | static void Exception_Assign(var self, var obj) {
function var (line 147) | static var Exception_Current(void) {
function Exception_Signal (line 151) | static void Exception_Signal(int sig) {
function jmp_buf (line 162) | static jmp_buf* Exception_Buffer(struct Exception* e) {
function Exception_Len (line 170) | static size_t Exception_Len(var self) {
function Exception_Running (line 175) | static bool Exception_Running(var self) {
function Exception_Backtrace (line 183) | static void Exception_Backtrace(void) {
function Exception_Backtrace (line 204) | static void Exception_Backtrace(void) {
function Exception_Backtrace (line 308) | static void Exception_Backtrace(void) {}
function Exception_Backtrace (line 314) | static void Exception_Backtrace(void) {}
function Exception_Error (line 318) | static void Exception_Error(struct Exception* e) {
function Exception_Show (line 333) | static int Exception_Show(var self, var out, int pos) {
function exception_signals (line 350) | void exception_signals(void) {
function exception_try (line 359) | void exception_try(jmp_buf* env) {
function var (line 370) | var exception_throw(var obj, const char* fmt, var args) {
function var (line 387) | var exception_catch(var args) {
function exception_try_end (line 416) | void exception_try_end(void) {
function exception_try_fail (line 425) | void exception_try_fail(void) {
FILE: src/File.c
type Example (line 31) | struct Example
type Example (line 33) | struct Example
type Method (line 52) | struct Method
type Method (line 54) | struct Method
function var (line 98) | var sopen(var self, var resource, var options) {
function sclose (line 102) | void sclose(var self) {
function sseek (line 106) | void sseek(var self, int64_t pos, int origin) {
function stell (line 110) | int64_t stell(var self) {
function sflush (line 114) | void sflush(var self) {
function seof (line 118) | bool seof(var self) {
function sread (line 122) | size_t sread(var self, void* output, size_t size) {
function swrite (line 126) | size_t swrite(var self, void* input, size_t size) {
type Example (line 151) | struct Example
type Example (line 153) | struct Example
function File_New (line 187) | static void File_New(var self, var args) {
function File_Del (line 194) | static void File_Del(var self) {
function var (line 199) | static var File_Open(var self, var filename, var access) {
function File_Close (line 213) | static void File_Close(var self) {
function File_Seek (line 224) | static void File_Seek(var self, int64_t pos, int origin) {
function File_Tell (line 238) | static int64_t File_Tell(var self) {
function File_Flush (line 253) | static void File_Flush(var self) {
function File_EOF (line 267) | static bool File_EOF(var self) {
function File_Read (line 277) | static size_t File_Read(var self, void* output, size_t size) {
function File_Write (line 293) | static size_t File_Write(var self, void* input, size_t size) {
function File_Format_To (line 308) | static int File_Format_To(var self, int pos, const char* fmt, va_list va) {
function File_Format_From (line 318) | static int File_Format_From(var self, int pos, const char* fmt, va_list ...
type Example (line 363) | struct Example
type Example (line 365) | struct Example
function Process_New (line 385) | static void Process_New(var self, var args) {
function Process_Del (line 391) | static void Process_Del(var self) {
function var (line 396) | static var Process_Open(var self, var filename, var access) {
function Process_Close (line 410) | static void Process_Close(var self) {
function Process_Seek (line 421) | static void Process_Seek(var self, int64_t pos, int origin) {
function Process_Tell (line 435) | static int64_t Process_Tell(var self) {
function Process_Flush (line 450) | static void Process_Flush(var self) {
function Process_EOF (line 464) | static bool Process_EOF(var self) {
function Process_Read (line 474) | static size_t Process_Read(var self, void* output, size_t size) {
function Process_Write (line 490) | static size_t Process_Write(var self, void* input, size_t size) {
function Process_Format_To (line 505) | static int Process_Format_To(var self, int pos, const char* fmt, va_list...
function Process_Format_From (line 515) | static int Process_Format_From(var self, int pos, const char* fmt, va_li...
FILE: src/Function.c
type Example (line 23) | struct Example
type Example (line 25) | struct Example
type Method (line 45) | struct Method
type Method (line 47) | struct Method
function var (line 64) | var call_with(var self, var args) {
type Example (line 85) | struct Example
type Example (line 87) | struct Example
function var (line 132) | static var Function_Call(var self, var args) {
FILE: src/GC.c
type Method (line 32) | struct Method
type Method (line 34) | struct Method
function mark (line 50) | void mark(var self, var gc, void(*f)(var,void*)) {
type Example (line 90) | struct Example
type Example (line 92) | struct Example
type GCEntry (line 108) | struct GCEntry {
type GC (line 115) | struct GC {
function GC_Probe (line 128) | static uint64_t GC_Probe(struct GC* gc, uint64_t i, uint64_t h) {
function GC_Ideal_Size (line 138) | static size_t GC_Ideal_Size(size_t size) {
type GC (line 149) | struct GC
function GC_Rehash (line 151) | static void GC_Rehash(struct GC* gc, size_t new_size) {
function GC_Resize_More (line 176) | static void GC_Resize_More(struct GC* gc) {
function GC_Resize_Less (line 182) | static void GC_Resize_Less(struct GC* gc) {
function GC_Hash (line 188) | static uint64_t GC_Hash(var ptr) {
function GC_Set_Ptr (line 192) | static void GC_Set_Ptr(struct GC* gc, var ptr, bool root) {
function GC_Mem_Ptr (line 219) | static bool GC_Mem_Ptr(struct GC* gc, var ptr) {
function GC_Rem_Ptr (line 235) | static void GC_Rem_Ptr(struct GC* gc, var ptr) {
type GC (line 280) | struct GC
function GC_Mark_And_Recurse (line 282) | static void GC_Mark_And_Recurse(void* _gc, void* ptr) {
function GC_Recurse (line 288) | static void GC_Recurse(struct GC* gc, var ptr) {
type GC (line 310) | struct GC
function GC_Mark_Item (line 312) | static void GC_Mark_Item(void* _gc, void* ptr) {
function GC_Mark_Stack (line 339) | static void CELLO_NASAN GC_Mark_Stack(struct GC* gc) {
function GC_Mark_Stack_Fake (line 361) | static void GC_Mark_Stack_Fake(struct GC* gc) { }
function GC_Mark (line 363) | void GC_Mark(struct GC* gc) {
function GC_Show (line 399) | static int GC_Show(var self, var out, int pos) {
function GC_Sweep (line 418) | void GC_Sweep(struct GC* gc) {
function var (line 478) | static var GC_Current(void) {
function GC_New (line 482) | static void GC_New(var self, var args) {
function GC_Del (line 494) | static void GC_Del(var self) {
function GC_Set (line 502) | static void GC_Set(var self, var key, var val) {
function GC_Rem (line 516) | static void GC_Rem(var self, var key) {
function GC_Mem (line 524) | static bool GC_Mem(var self, var key) {
function GC_Start (line 528) | static void GC_Start(var self) {
function GC_Stop (line 533) | static void GC_Stop(var self) {
function GC_Running (line 538) | static bool GC_Running(var self) {
function Cello_Exit (line 553) | void Cello_Exit(void) {
FILE: src/Get.c
type Example (line 32) | struct Example
type Example (line 34) | struct Example
type Method (line 65) | struct Method
type Method (line 67) | struct Method
function var (line 103) | var get(var self, var key) {
function set (line 107) | void set(var self, var key, var val) {
function mem (line 111) | bool mem(var self, var key) {
function rem (line 115) | void rem(var self, var key) {
function var (line 119) | var key_type(var self) {
function var (line 123) | var val_type(var self) {
FILE: src/Hash.c
type Example (line 35) | struct Example
type Example (line 37) | struct Example
type Method (line 56) | struct Method
type Method (line 58) | struct Method
function hash_data (line 79) | uint64_t hash_data(const void* data, size_t size) {
function hash (line 118) | uint64_t hash(var self) {
FILE: src/Iter.c
type Example (line 36) | struct Example
type Example (line 38) | struct Example
type Method (line 64) | struct Method
type Method (line 66) | struct Method
function var (line 98) | var iter_init(var self) {
function var (line 102) | var iter_next(var self, var curr) {
function var (line 106) | var iter_last(var self) {
function var (line 110) | var iter_prev(var self, var curr) {
function var (line 114) | var iter_type(var self) {
type Example (line 148) | struct Example
type Example (line 150) | struct Example
type Method (line 179) | struct Method
type Method (line 181) | struct Method
function var (line 192) | var range_stack(var self, var args) {
function Range_New (line 228) | static void Range_New(var self, var args) {
function Range_Del (line 234) | static void Range_Del(var self) {
function Range_Assign (line 239) | static void Range_Assign(var self, var obj) {
function Range_Cmp (line 248) | static int Range_Cmp(var self, var obj) {
function var (line 254) | static var Range_Iter_Init(var self) {
function var (line 265) | static var Range_Iter_Last(var self) {
function var (line 276) | static var Range_Iter_Next(var self, var curr) {
function var (line 286) | static var Range_Iter_Prev(var self, var curr) {
function var (line 296) | static var Range_Iter_Type(var self) {
function Range_Len (line 300) | static size_t Range_Len(var self) {
function var (line 308) | static var Range_Get(var self, var key) {
function Range_Mem (line 335) | static bool Range_Mem(var self, var key) {
function Range_Show (line 349) | static int Range_Show(var self, var output, int pos) {
type Example (line 401) | struct Example
type Example (line 403) | struct Example
type Method (line 435) | struct Method
type Method (line 437) | struct Method
function Slice_Arg (line 453) | static int64_t Slice_Arg(int part, size_t n, var arg) {
function var (line 472) | var slice_stack(var self, var args) {
function Slice_New (line 517) | static void Slice_New(var self, var args) {
function Slice_Del (line 523) | static void Slice_Del(var self) {
function Slice_Assign (line 528) | static void Slice_Assign(var self, var obj) {
function Slice_Cmp (line 535) | static int Slice_Cmp(var self, var obj) {
function var (line 543) | static var Slice_Iter_Init(var self) {
function var (line 566) | static var Slice_Iter_Next(var self, var curr) {
function var (line 585) | static var Slice_Iter_Type(var self) {
function var (line 590) | static var Slice_Iter_Last(var self) {
function var (line 613) | static var Slice_Iter_Prev(var self, var curr) {
function Slice_Len (line 632) | static size_t Slice_Len(var self) {
function var (line 637) | static var Slice_Get(var self, var key) {
function Slice_Mem (line 642) | static bool Slice_Mem(var self, var key) {
function Slice_Show (line 651) | static int Slice_Show(var self, var output, int pos) {
type Example (line 703) | struct Example
type Example (line 705) | struct Example
type Method (line 727) | struct Method
type Method (line 729) | struct Method
function var (line 744) | var zip_stack(var self) {
function Zip_New (line 755) | static void Zip_New(var self, var args) {
function Zip_Del (line 765) | static void Zip_Del(var self) {
function Zip_Assign (line 771) | static void Zip_Assign(var self, var obj) {
function var (line 778) | static var Zip_Iter_Init(var self) {
function var (line 792) | static var Zip_Iter_Last(var self) {
function var (line 806) | static var Zip_Iter_Next(var self, var curr) {
function var (line 820) | static var Zip_Iter_Prev(var self, var curr) {
function var (line 834) | static var Zip_Iter_Type(var self) {
function Zip_Len (line 838) | static size_t Zip_Len(var self) {
function var (line 852) | static var Zip_Get(var self, var key) {
function Zip_Mem (line 865) | static bool Zip_Mem(var self, var key) {
function var (line 884) | var enumerate_stack(var self) {
type Example (line 915) | struct Example
type Example (line 917) | struct Example
type Method (line 949) | struct Method
type Method (line 951) | struct Method
function Filter_New (line 963) | static void Filter_New(var self, var args) {
function var (line 969) | static var Filter_Iter_Init(var self) {
function var (line 982) | static var Filter_Iter_Last(var self) {
function var (line 995) | static var Filter_Iter_Next(var self, var curr) {
function var (line 1008) | static var Filter_Iter_Prev(var self, var curr) {
function var (line 1021) | static var Filter_Iter_Type(var self) {
function Filter_Mem (line 1026) | static bool Filter_Mem(var self, var key) {
type Method (line 1077) | struct Method
type Method (line 1079) | struct Method
type Example (line 1091) | struct Example
type Example (line 1093) | struct Example
function Map_New (line 1124) | static void Map_New(var self, var args) {
function var (line 1130) | static var Map_Iter_Init(var self) {
function var (line 1140) | static var Map_Iter_Last(var self) {
function var (line 1150) | static var Map_Iter_Next(var self, var curr) {
function var (line 1160) | static var Map_Iter_Prev(var self, var curr) {
function Map_Len (line 1170) | static size_t Map_Len(var self) {
function var (line 1175) | static var Map_Get(var self, var key) {
function Map_Mem (line 1185) | static bool Map_Mem(var self, var key) {
function var (line 1192) | static var Map_Call(var self, var args) {
FILE: src/Len.c
type Example (line 25) | struct Example
type Example (line 27) | struct Example
type Method (line 41) | struct Method
type Method (line 43) | struct Method
function len (line 59) | size_t len(var self) {
function empty (line 63) | bool empty(var self) {
FILE: src/List.c
type Example (line 29) | struct Example
type Example (line 31) | struct Example
type List (line 80) | struct List {
function var (line 88) | static var List_Alloc(struct List* l) {
function List_Free (line 101) | static void List_Free(struct List* l, var self) {
function var (line 105) | static var* List_Next(struct List* l, var self) {
function var (line 109) | static var* List_Prev(struct List* l, var self) {
function var (line 113) | static var List_At(struct List* l, int64_t i) {
function List_New (line 142) | static void List_New(var self, var args) {
function List_Clear (line 158) | static void List_Clear(var self) {
function List_Del (line 172) | static void List_Del(var self) {
function List_Assign (line 177) | static void List_Assign(var self, var obj) {
function List_Concat (line 192) | static void List_Concat(var self, var obj) {
function List_Cmp (line 201) | static int List_Cmp(var self, var obj) {
function List_Hash (line 220) | static uint64_t List_Hash(var self) {
function List_Len (line 233) | static size_t List_Len(var self) {
function List_Mem (line 238) | static bool List_Mem(var self, var obj) {
function List_Unlink (line 248) | static void List_Unlink(struct List* l, var item) {
function List_Link (line 268) | static void List_Link(struct List* l, var item, var prev, var next) {
function List_Pop_At (line 275) | static void List_Pop_At(var self, var key) {
function List_Rem (line 287) | static void List_Rem(var self, var obj) {
function List_Push (line 304) | static void List_Push(var self, var obj) {
function List_Push_At (line 312) | static void List_Push_At(var self, var obj, var key) {
function List_Pop (line 328) | static void List_Pop(var self) {
function var (line 346) | static var List_Get(var self, var key) {
function List_Set (line 351) | static void List_Set(var self, var key, var val) {
function var (line 356) | static var List_Iter_Init(var self) {
function var (line 362) | static var List_Iter_Next(var self, var curr) {
function var (line 368) | static var List_Iter_Last(var self) {
function var (line 374) | static var List_Iter_Prev(var self, var curr) {
function var (line 380) | static var List_Iter_Type(var self) {
function List_Show (line 385) | static int List_Show(var self, var output, int pos) {
function List_Resize (line 397) | static void List_Resize(var self, size_t n) {
function List_Mark (line 421) | static void List_Mark(var self, var gc, void(*f)(var,void*)) {
FILE: src/Num.c
type Example (line 24) | struct Example
type Example (line 26) | struct Example
type Method (line 38) | struct Method
type Method (line 40) | struct Method
type Example (line 77) | struct Example
type Example (line 79) | struct Example
type Method (line 91) | struct Method
type Method (line 93) | struct Method
function c_int (line 109) | int64_t c_int(var self) {
function c_float (line 118) | double c_float(var self) {
type Example (line 146) | struct Example
type Example (line 148) | struct Example
function Int_Assign (line 165) | static void Int_Assign(var self, var obj) {
function Int_C_Int (line 170) | static int64_t Int_C_Int(var self) {
function Int_Cmp (line 175) | static int Int_Cmp(var self, var obj) {
function Int_Hash (line 179) | static uint64_t Int_Hash(var self) {
function Int_Show (line 183) | static int Int_Show(var self, var output, int pos) {
function Int_Look (line 187) | static int Int_Look(var self, var input, int pos) {
type Example (line 219) | struct Example
type Example (line 221) | struct Example
function Float_Assign (line 238) | static void Float_Assign(var self, var obj) {
function Float_C_Float (line 243) | static double Float_C_Float(var self) {
function Float_Cmp (line 248) | static int Float_Cmp(var self, var obj) {
function Float_Hash (line 258) | static uint64_t Float_Hash(var self) {
function Float_Show (line 264) | int Float_Show(var self, var output, int pos) {
function Float_Look (line 268) | int Float_Look(var self, var input, int pos) {
FILE: src/Pointer.c
type Example (line 26) | struct Example
type Example (line 28) | struct Example
type Method (line 46) | struct Method
type Method (line 48) | struct Method
function ref (line 68) | void ref(var self, var item) {
function var (line 72) | var deref(var self) {
type Example (line 99) | struct Example
type Example (line 101) | struct Example
function Ref_Assign (line 132) | static void Ref_Assign(var self, var obj) {
function Ref_Ref (line 141) | static void Ref_Ref(var self, var val) {
function var (line 146) | static var Ref_Deref(var self) {
type Example (line 188) | struct Example
type Example (line 190) | struct Example
function Box_New (line 233) | static void Box_New(var self, var args) {
function Box_Del (line 237) | static void Box_Del(var self) {
function Box_Assign (line 243) | static void Box_Assign(var self, var obj) {
function Box_Show (line 252) | static int Box_Show(var self, var output, int pos) {
function Box_Ref (line 256) | static void Box_Ref(var self, var val) {
function var (line 261) | static var Box_Deref(var self) {
FILE: src/Push.c
type Example (line 30) | struct Example
type Example (line 32) | struct Example
type Method (line 56) | struct Method
type Method (line 58) | struct Method
function push (line 86) | void push(var self, var val) { method(self, Push, push, val); }
function push_at (line 87) | void push_at(var self, var val, var i) { method(self, Push, push_at, val...
function pop (line 88) | void pop(var self) { method(self, Push, pop); }
function pop_at (line 89) | void pop_at(var self, var i) { method(self, Push, pop_at, i); }
FILE: src/Resize.c
type Method (line 28) | struct Method
type Method (line 30) | struct Method
type Example (line 42) | struct Example
type Example (line 44) | struct Example
function resize (line 68) | void resize(var self, size_t n) {
FILE: src/Show.c
type Example (line 33) | struct Example
type Example (line 35) | struct Example
type Method (line 48) | struct Method
type Method (line 50) | struct Method
function format_to_va (line 72) | int format_to_va(var self, int pos, const char* fmt, va_list va) {
function format_from_va (line 76) | int format_from_va(var self, int pos, const char* fmt, va_list va) {
function format_to (line 80) | int format_to(var self, int pos, const char* fmt, ...) {
function format_from (line 88) | int format_from(var self, int pos, const char* fmt, ...) {
type Example (line 136) | struct Example
type Example (line 138) | struct Example
type Method (line 173) | struct Method
type Method (line 175) | struct Method
function show (line 217) | int show(var self) {
function show_to (line 221) | int show_to(var self, var out, int pos) {
function print_with (line 235) | int print_with(const char* fmt, var args) {
function println_with (line 239) | int println_with(const char* fmt, var args) {
function print_to_with (line 246) | int print_to_with(var out, int pos, const char* fmt, var args) {
function look (line 337) | int look(var self) {
function look_from (line 341) | int look_from(var self, var input, int pos) {
function scan_with (line 345) | int scan_with(const char* fmt, var args) {
function scanln_with (line 349) | int scanln_with(const char* fmt, var args) {
function scan_from_with (line 356) | int scan_from_with(var input, int pos, const char* fmt, var args) {
FILE: src/Start.c
type Example (line 33) | struct Example
type Example (line 35) | struct Example
type Method (line 55) | struct Method
type Method (line 57) | struct Method
function start (line 88) | void start(var self) {
function stop (line 92) | void stop(var self) {
function join (line 96) | void join(var self) {
function running (line 100) | bool running(var self) {
function var (line 104) | var start_in(var self) {
function var (line 112) | var stop_in(var self) {
FILE: src/String.c
type Example (line 24) | struct Example
type Example (line 26) | struct Example
type Method (line 38) | struct Method
type Method (line 40) | struct Method
type String (line 59) | struct String
type Example (line 89) | struct Example
type Example (line 91) | struct Example
function String_New (line 126) | static void String_New(var self, var args) {
function String_Del (line 141) | static void String_Del(var self) {
function String_Assign (line 154) | static void String_Assign(var self, var obj) {
type String (line 177) | struct String
function String_Cmp (line 181) | static int String_Cmp(var self, var obj) {
function String_Len (line 185) | static size_t String_Len(var self) {
function String_Clear (line 190) | static void String_Clear(var self) {
function String_Mem (line 211) | static bool String_Mem(var self, var obj) {
function String_Rem (line 221) | static void String_Rem(var self, var obj) {
function String_Hash (line 233) | static uint64_t String_Hash(var self) {
function String_Concat (line 238) | static void String_Concat(var self, var obj) {
function String_Resize (line 259) | static void String_Resize(var self, size_t n) {
function String_Format_To (line 286) | static int String_Format_To(var self, int pos, const char* fmt, va_list ...
function String_Format_From (line 371) | static int String_Format_From(var self, int pos, const char* fmt, va_lis...
function String_Show (line 376) | static int String_Show(var self, var out, int pos) {
function String_Look (line 400) | static int String_Look(var self, var input, int pos) {
FILE: src/Table.c
type Example (line 26) | struct Example
type Example (line 28) | struct Example
type Table (line 67) | struct Table {
function Table_Ideal_Size (line 94) | static size_t Table_Ideal_Size(size_t size) {
function Table_Step (line 105) | static size_t Table_Step(struct Table* t) {
function Table_Key_Hash (line 112) | static uint64_t Table_Key_Hash(struct Table* t, uint64_t i) {
function var (line 116) | static var Table_Key(struct Table* t, uint64_t i) {
function var (line 122) | static var Table_Val(struct Table* t, uint64_t i) {
function Table_Probe (line 130) | static uint64_t Table_Probe(struct Table* t, uint64_t i, uint64_t h) {
function Table_Size_Round (line 141) | static size_t Table_Size_Round(size_t s) {
function Table_New (line 145) | static void Table_New(var self, var args) {
function Table_Del (line 185) | static void Table_Del(var self) {
function var (line 201) | static var Table_Key_Type(var self) {
function var (line 206) | static var Table_Val_Type(var self) {
function Table_Clear (line 211) | static void Table_Clear(var self) {
function Table_Assign (line 229) | static void Table_Assign(var self, var obj) {
function Table_Cmp (line 270) | static int Table_Cmp(var self, var obj) {
function Table_Hash (line 294) | static uint64_t Table_Hash(var self) {
function Table_Len (line 308) | static size_t Table_Len(var self) {
function Table_Swapspace_Hash (line 313) | static uint64_t Table_Swapspace_Hash(struct Table* t, var space) {
function var (line 317) | static var Table_Swapspace_Key(struct Table* t, var space) {
function var (line 321) | static var Table_Swapspace_Val(struct Table* t, var space) {
function Table_Set_Move (line 326) | static void Table_Set_Move(var self, var key, var val, bool move) {
function Table_Rehash (line 398) | static void Table_Rehash(struct Table* t, size_t new_size) {
function Table_Resize_More (line 431) | static void Table_Resize_More(struct Table* t) {
function Table_Resize_Less (line 437) | static void Table_Resize_Less(struct Table* t) {
function Table_Mem (line 443) | static bool Table_Mem(var self, var key) {
function Table_Rem (line 469) | static void Table_Rem(var self, var key) {
function var (line 520) | static var Table_Get(var self, var key) {
function Table_Set (line 553) | static void Table_Set(var self, var key, var val) {
function var (line 558) | static var Table_Iter_Init(var self) {
function var (line 571) | static var Table_Iter_Next(var self, var curr) {
function var (line 588) | static var Table_Iter_Last(var self) {
function var (line 606) | static var Table_Iter_Prev(var self, var curr) {
function var (line 623) | static var Table_Iter_Type(var self) {
function Table_Show (line 628) | static int Table_Show(var self, var output, int pos) {
function Table_Resize (line 646) | static void Table_Resize(var self, size_t n) {
function Table_Mark (line 665) | static void Table_Mark(var self, var gc, void(*f)(var,void*)) {
FILE: src/Thread.c
type Example (line 29) | struct Example
type Example (line 31) | struct Example
type Method (line 45) | struct Method
type Method (line 47) | struct Method
function var (line 63) | var current(var type) {
type Thread (line 67) | struct Thread {
type Example (line 100) | struct Example
type Example (line 102) | struct Example
function Thread_New (line 153) | static void Thread_New(var self, var args) {
function Thread_Del (line 162) | static void Thread_Del(var self) {
function Thread_C_Int (line 173) | static int64_t Thread_C_Int(var self) {
function Thread_Assign (line 190) | static void Thread_Assign(var self, var obj) {
function Thread_Cmp (line 198) | static int Thread_Cmp(var self, var obj) {
function Thread_Hash (line 202) | static uint64_t Thread_Hash(var self) {
function Thread_TLS_Key_Create (line 212) | static void Thread_TLS_Key_Create(void) {
function Thread_TLS_Key_Delete (line 215) | static void Thread_TLS_Key_Delete(void) {
function var (line 219) | static var Thread_Init_Run(var self) {
function Thread_TLS_Key_Create (line 249) | static void Thread_TLS_Key_Create(void) {
function Thread_TLS_Key_Delete (line 252) | static void Thread_TLS_Key_Delete(void) {
function DWORD (line 256) | static DWORD Thread_Init_Run(var self) {
function var (line 284) | static var Thread_Call(var self, var args) {
function Thread_Main_Del (line 346) | static void Thread_Main_Del(void) {
function var (line 351) | static var Thread_Current(void) {
function Thread_Start (line 405) | static void Thread_Start(var self) {
function Thread_Stop (line 409) | static void Thread_Stop(var self) {
function Thread_Join (line 424) | static void Thread_Join(var self) {
function Thread_Running (line 439) | static bool Thread_Running(var self) {
function var (line 444) | static var Thread_Get(var self, var key) {
function Thread_Set (line 449) | static void Thread_Set(var self, var key, var val) {
function Thread_Mem (line 454) | static bool Thread_Mem(var self, var key) {
function Thread_Rem (line 459) | static void Thread_Rem(var self, var key) {
function var (line 464) | static var Thread_Key_Type(var self) {
function var (line 469) | static var Thread_Val_Type(var self) {
function Thread_Mark (line 474) | static void Thread_Mark(var self, var gc, void(*f)(var,void*)) {
type Method (line 518) | struct Method
type Method (line 520) | struct Method
type Example (line 540) | struct Example
type Example (line 542) | struct Example
function lock (line 561) | void lock(var self) {
function unlock (line 565) | void unlock(var self) {
function trylock (line 569) | bool trylock(var self) {
type Mutex (line 573) | struct Mutex {
type Example (line 595) | struct Example
type Example (line 597) | struct Example
function Mutex_New (line 611) | static void Mutex_New(var self, var args) {
function Mutex_Del (line 620) | static void Mutex_Del(var self) {
function Mutex_Lock (line 629) | static void Mutex_Lock(var self) {
function Mutex_Trylock (line 647) | static bool Mutex_Trylock(var self) {
function Mutex_Unlock (line 664) | static void Mutex_Unlock(var self) {
FILE: src/Tree.c
type Example (line 26) | struct Example
type Example (line 28) | struct Example
type Tree (line 67) | struct Tree {
type Tree (line 76) | struct Tree
function var (line 78) | static var* Tree_Left(struct Tree* m, var node) {
function var (line 82) | static var* Tree_Right(struct Tree* m, var node) {
function var (line 86) | static var Tree_Get_Parent(struct Tree* m, var node) {
function Tree_Set_Parent (line 91) | static void Tree_Set_Parent(struct Tree* m, var node, var ptr) {
function var (line 99) | static var Tree_Key(struct Tree* m, var node) {
function var (line 103) | static var Tree_Val(struct Tree* m, var node) {
function Tree_Set_Color (line 109) | static void Tree_Set_Color(struct Tree* m, var node, bool col) {
function Tree_Get_Color (line 118) | static bool Tree_Get_Color(struct Tree* m, var node) {
function Tree_Set_Black (line 124) | static void Tree_Set_Black(struct Tree* m, var node) {
function Tree_Set_Red (line 128) | static void Tree_Set_Red(struct Tree* m, var node) {
function Tree_Is_Red (line 132) | static bool Tree_Is_Red(struct Tree* m, var node) {
function Tree_Is_Black (line 136) | static bool Tree_Is_Black(struct Tree* m, var node) {
function var (line 140) | static var Tree_Alloc(struct Tree* m) {
function Tree_New (line 167) | static void Tree_New(var self, var args) {
function Tree_Clear_Entry (line 190) | static void Tree_Clear_Entry(struct Tree* m, var node) {
function Tree_Clear (line 200) | static void Tree_Clear(var self) {
function Tree_Del (line 207) | static void Tree_Del(var self) {
function Tree_Assign (line 212) | static void Tree_Assign(var self, var obj) {
function Tree_Cmp (line 230) | static int Tree_Cmp(var self, var obj) {
function Tree_Hash (line 254) | static uint64_t Tree_Hash(var self) {
function Tree_Len (line 268) | static size_t Tree_Len(var self) {
function Tree_Mem (line 273) | static bool Tree_Mem(var self, var key) {
function var (line 287) | static var Tree_Get(var self, var key) {
function var (line 301) | static var Tree_Key_Type(var self) {
function var (line 306) | static var Tree_Val_Type(var self) {
function var (line 311) | static var Tree_Maximum(struct Tree* m, var node) {
function var (line 318) | static var Tree_Sibling(struct Tree* m, var node) {
function var (line 331) | static var Tree_Grandparent(struct Tree* m, var node) {
function var (line 339) | static var Tree_Uncle(struct Tree* m, var node) {
function Tree_Replace (line 349) | void Tree_Replace(struct Tree* m, var oldn, var newn) {
function Tree_Rotate_Left (line 364) | static void Tree_Rotate_Left(struct Tree* m, var node) {
function Tree_Rotate_Right (line 375) | static void Tree_Rotate_Right(struct Tree* m, var node) {
function Tree_Set_Fix (line 386) | static void Tree_Set_Fix(struct Tree* m, var node) {
function Tree_Set (line 435) | static void Tree_Set(var self, var key, var val) {
function Tree_Rem_Fix (line 498) | static void Tree_Rem_Fix(struct Tree* m, var node) {
function Tree_Rem (line 573) | static void Tree_Rem(var self, var key) {
function var (line 625) | static var Tree_Iter_Init(var self) {
function var (line 635) | static var Tree_Iter_Next(var self, var curr) {
function var (line 661) | static var Tree_Iter_Last(var self) {
function var (line 671) | static var Tree_Iter_Prev(var self, var curr) {
function var (line 697) | static var Tree_Iter_Type(var self) {
function Tree_Show (line 702) | static int Tree_Show(var self, var output, int pos) {
function Tree_Mark (line 720) | static void Tree_Mark(var self, var gc, void(*f)(var,void*)) {
function Tree_Resize (line 734) | static void Tree_Resize(var self, size_t n) {
FILE: src/Tuple.c
type Example (line 40) | struct Example
type Example (line 42) | struct Example
type Method (line 61) | struct Method
type Method (line 63) | struct Method
function Tuple_New (line 74) | static void Tuple_New(var self, var args) {
function Tuple_Del (line 93) | static void Tuple_Del(var self) {
function Tuple_Assign (line 108) | static void Tuple_Assign(var self, var obj) {
function Tuple_Len (line 146) | static size_t Tuple_Len(var self) {
function var (line 153) | static var Tuple_Iter_Init(var self) {
function var (line 158) | static var Tuple_Iter_Next(var self, var curr) {
function var (line 168) | static var Tuple_Iter_Last(var self) {
function var (line 173) | static var Tuple_Iter_Prev(var self, var curr) {
function var (line 184) | static var Tuple_Get(var self, var key) {
function Tuple_Set (line 202) | static void Tuple_Set(var self, var key, var val) {
function Tuple_Mem (line 221) | static bool Tuple_Mem(var self, var item) {
function Tuple_Rem (line 230) | static void Tuple_Rem(var self, var item) {
function Tuple_Show (line 242) | static int Tuple_Show(var self, var output, int pos) {
function Tuple_Push (line 254) | static void Tuple_Push(var self, var obj) {
function Tuple_Pop (line 279) | static void Tuple_Pop(var self) {
function Tuple_Push_At (line 303) | static void Tuple_Push_At(var self, var obj, var key) {
function Tuple_Pop_At (line 340) | static void Tuple_Pop_At(var self, var key) {
function Tuple_Concat (line 368) | static void Tuple_Concat(var self, var obj) {
function Tuple_Resize (line 399) | static void Tuple_Resize(var self, size_t n) {
function Tuple_Mark (line 422) | static void Tuple_Mark(var self, var gc, void(*f)(var,void*)) {
function Tuple_Swap (line 431) | static void Tuple_Swap(struct Tuple* t, size_t i, size_t j) {
function Tuple_Sort_Partition (line 437) | static size_t Tuple_Sort_Partition(
function Tuple_Sort_Part (line 455) | static void Tuple_Sort_Part(
function Tuple_Sort_By (line 464) | static void Tuple_Sort_By(var self, bool(*f)(var,var)) {
function Tuple_Cmp (line 468) | static int Tuple_Cmp(var self, var obj) {
function Tuple_Hash (line 490) | static uint64_t Tuple_Hash(var self) {
FILE: src/Type.c
type Example (line 26) | struct Example
type Example (line 28) | struct Example
type Method (line 41) | struct Method
type Method (line 43) | struct Method
function var (line 59) | var cast(var self, var type) {
type Example (line 99) | struct Example
type Example (line 101) | struct Example
type Method (line 119) | struct Method
type Method (line 121) | struct Method
function var (line 161) | static var Type_Alloc(void) {
function Type_New (line 178) | static void Type_New(var self, var args) {
type Type (line 210) | struct Type
function Type_Builtin_Size (line 214) | static size_t Type_Builtin_Size(struct Type* t) {
function Type_Show (line 218) | static int Type_Show(var self, var output, int pos) {
function Type_Cmp (line 222) | static int Type_Cmp(var self, var obj) {
function Type_Hash (line 227) | static uint64_t Type_Hash(var self) {
function Type_Assign (line 236) | static void Type_Assign(var self, var obj) {
function var (line 240) | static var Type_Copy(var self) {
function print_indent (line 244) | static int print_indent(var out, int pos, const char* str) {
function Type_Help_To (line 254) | static int Type_Help_To(var self, var out, int pos) {
function var (line 319) | static var Type_Scan(var self, var cls) {
function Type_Implements (line 345) | static bool Type_Implements(var self, var cls) {
function type_implements (line 349) | bool type_implements(var self, var cls) {
function var (line 355) | static var Type_Method_At_Offset(
function var (line 382) | var type_method_at_offset(
function Type_Implements_Method_At_Offset (line 387) | static bool Type_Implements_Method_At_Offset(var self, var cls, size_t o...
function type_implements_method_at_offset (line 395) | bool type_implements_method_at_offset(var self, var cls, size_t offset) {
function var (line 434) | static var Type_Instance(var self, var cls) {
function var (line 453) | var type_instance(var self, var cls) {
function var (line 457) | static var Type_Of(var self) {
function var (line 497) | var type_of(var self) {
function var (line 501) | var instance(var self, var cls) {
function implements (line 505) | bool implements(var self, var cls) {
function var (line 509) | var method_at_offset(
function implements_method_at_offset (line 514) | bool implements_method_at_offset(var self, var cls, size_t offset) {
type Example (line 544) | struct Example
type Example (line 546) | struct Example
type Method (line 559) | struct Method
type Method (line 561) | struct Method
function size (line 576) | size_t size(var type) {
FILE: tests/ptest.c
function pt_color (line 59) | static void pt_color(int color) {
function pt_color (line 95) | static void pt_color(int color) {
function pt_assert_run (line 111) | void pt_assert_run(
function ptest_signal (line 130) | static void ptest_signal(int sig) {
function pt_title_case (line 161) | static void pt_title_case(char* output, const char* input) {
type test_t (line 188) | typedef struct {
function pt_add_test (line 200) | void pt_add_test(void (*func)(void), const char* name, const char* suite) {
function pt_add_suite (line 233) | void pt_add_suite(void (*func)(void)) {
function pt_run (line 243) | int pt_run(void) {
FILE: tests/test.c
function PT_FUNC (line 6) | PT_FUNC(test_array_new) {
function PT_FUNC (line 30) | PT_FUNC(test_array_assign) {
function PT_FUNC (line 59) | PT_FUNC(test_array_concat) {
function PT_FUNC (line 81) | PT_FUNC(test_array_cmp) {
function PT_FUNC (line 96) | PT_FUNC(test_array_get) {
function PT_FUNC (line 145) | PT_FUNC(test_array_hash) {
function PT_FUNC (line 155) | PT_FUNC(test_array_iter) {
function PT_FUNC (line 196) | PT_FUNC(test_array_len) {
function PT_FUNC (line 214) | PT_FUNC(test_array_push) {
function PT_FUNC (line 272) | PT_FUNC(test_array_resize) {
function PT_FUNC (line 291) | PT_FUNC(test_array_show) {
function PT_FUNC (line 301) | PT_FUNC(test_array_sort) {
function PT_SUITE (line 328) | PT_SUITE(suite_array) {
function PT_FUNC (line 345) | PT_FUNC(test_box_new) {
function PT_FUNC (line 358) | PT_FUNC(test_box_assign) {
function PT_FUNC (line 370) | PT_FUNC(test_box_pointer) {
function PT_FUNC (line 385) | PT_FUNC(test_box_show) {
function PT_SUITE (line 396) | PT_SUITE(suite_box) {
function PT_FUNC (line 405) | PT_FUNC(test_file_format) {
function PT_FUNC (line 415) | PT_FUNC(test_file_new) {
function PT_FUNC (line 429) | PT_FUNC(test_file_start) {
function PT_FUNC (line 442) | PT_FUNC(test_file_stream) {
function PT_SUITE (line 462) | PT_SUITE(suite_file) {
function PT_FUNC (line 471) | PT_FUNC(test_float_assign) {
function PT_FUNC (line 495) | PT_FUNC(test_float_c_float) {
function PT_FUNC (line 505) | PT_FUNC(test_float_cmp) {
function PT_FUNC (line 527) | PT_FUNC(test_float_hash) {
function PT_FUNC (line 541) | PT_FUNC(test_float_show) {
function PT_SUITE (line 558) | PT_SUITE(suite_float) {
function var (line 568) | var greater_than_two(var x) {
function var (line 572) | var mem_hello(var x) {
function PT_FUNC (line 576) | PT_FUNC(test_filter_get) {
function PT_FUNC (line 590) | PT_FUNC(test_filter_iter) {
function PT_FUNC (line 606) | PT_FUNC(test_filter_new) {
function PT_SUITE (line 621) | PT_SUITE(suite_filter) {
function var (line 629) | var return_fst(var args) {
function var (line 633) | var return_snd(var args) {
function PT_FUNC (line 638) | PT_FUNC(test_function_call) {
function PT_SUITE (line 645) | PT_SUITE(suite_function) {
function PT_FUNC (line 651) | PT_FUNC(test_int_assign) {
function PT_FUNC (line 675) | PT_FUNC(test_int_c_int) {
function PT_FUNC (line 684) | PT_FUNC(test_int_cmp) {
function PT_FUNC (line 701) | PT_FUNC(test_int_hash) {
function PT_FUNC (line 710) | PT_FUNC(test_int_show) {
function PT_SUITE (line 727) | PT_SUITE(suite_int) {
function PT_FUNC (line 737) | PT_FUNC(test_list_new) {
function PT_FUNC (line 761) | PT_FUNC(test_list_assign) {
function PT_FUNC (line 790) | PT_FUNC(test_list_concat) {
function PT_FUNC (line 812) | PT_FUNC(test_list_cmp) {
function PT_FUNC (line 827) | PT_FUNC(test_list_get) {
function PT_FUNC (line 876) | PT_FUNC(test_list_hash) {
function PT_FUNC (line 886) | PT_FUNC(test_list_iter) {
function PT_FUNC (line 927) | PT_FUNC(test_list_len) {
function PT_FUNC (line 945) | PT_FUNC(test_list_push) {
function PT_FUNC (line 1003) | PT_FUNC(test_list_resize) {
function PT_FUNC (line 1022) | PT_FUNC(test_list_show) {
function PT_SUITE (line 1033) | PT_SUITE(suite_list) {
function var (line 1049) | var convert_to_int(var x) {
function var (line 1055) | var assert_value(var x) {
function PT_FUNC (line 1060) | PT_FUNC(test_map_call) {
function PT_FUNC (line 1067) | PT_FUNC(test_map_get) {
function PT_FUNC (line 1084) | PT_FUNC(test_map_iter) {
function PT_FUNC (line 1091) | PT_FUNC(test_map_len) {
function PT_FUNC (line 1103) | PT_FUNC(test_map_new) {
function PT_SUITE (line 1121) | PT_SUITE(suite_map) {
function var (line 1131) | static var increment(var args) {
function var (line 1140) | static var increment2(var args) {
function PT_FUNC (line 1149) | PT_FUNC(test_mutex_lock) {
function PT_FUNC (line 1176) | PT_FUNC(test_mutex_new) {
function PT_FUNC (line 1186) | PT_FUNC(test_mutex_start) {
function PT_SUITE (line 1213) | PT_SUITE(suite_mutex) {
function PT_FUNC (line 1221) | PT_FUNC(test_range_assign) {
function PT_FUNC (line 1233) | PT_FUNC(test_range_cmp) {
function PT_FUNC (line 1253) | PT_FUNC(test_range_get) {
function PT_FUNC (line 1277) | PT_FUNC(test_range_iter) {
function PT_FUNC (line 1306) | PT_FUNC(test_range_len) {
function PT_FUNC (line 1318) | PT_FUNC(test_range_new) {
function PT_FUNC (line 1323) | PT_FUNC(test_range_show) {
function PT_SUITE (line 1334) | PT_SUITE(suite_range) {
function PT_FUNC (line 1346) | PT_FUNC(test_ref_assign) {
function PT_FUNC (line 1358) | PT_FUNC(test_ref_pointer) {
function PT_SUITE (line 1373) | PT_SUITE(suite_ref) {
function PT_FUNC (line 1380) | PT_FUNC(test_slice_assign) {
function PT_FUNC (line 1395) | PT_FUNC(test_slice_cmp) {
function PT_FUNC (line 1410) | PT_FUNC(test_slice_get) {
function PT_FUNC (line 1457) | PT_FUNC(test_slice_iter) {
function PT_FUNC (line 1480) | PT_FUNC(test_slice_len) {
function PT_FUNC (line 1495) | PT_FUNC(test_slice_new) {
function PT_SUITE (line 1506) | PT_SUITE(suite_slice) {
function PT_FUNC (line 1517) | PT_FUNC(test_string_assign) {
function PT_FUNC (line 1531) | PT_FUNC(test_string_c_str) {
function PT_FUNC (line 1541) | PT_FUNC(test_string_cmp) {
function PT_FUNC (line 1558) | PT_FUNC(test_string_concat) {
function PT_FUNC (line 1576) | PT_FUNC(test_string_format) {
function PT_FUNC (line 1594) | PT_FUNC(test_string_get) {
function PT_FUNC (line 1617) | PT_FUNC(test_string_hash) {
function PT_FUNC (line 1629) | PT_FUNC(test_string_len) {
function PT_FUNC (line 1639) | PT_FUNC(test_string_new) {
function PT_FUNC (line 1663) | PT_FUNC(test_string_resize) {
function PT_FUNC (line 1683) | PT_FUNC(test_string_show) {
function PT_SUITE (line 1703) | PT_SUITE(suite_string) {
function PT_FUNC (line 1719) | PT_FUNC(test_table_assign) {
function PT_FUNC (line 1744) | PT_FUNC(test_table_cmp) {
function PT_FUNC (line 1774) | PT_FUNC(test_table_get) {
function PT_FUNC (line 1836) | PT_FUNC(test_table_hash) {
function PT_FUNC (line 1850) | PT_FUNC(test_table_iter) {
function PT_FUNC (line 1870) | PT_FUNC(test_table_len) {
function PT_FUNC (line 1882) | PT_FUNC(test_table_new) {
function PT_FUNC (line 1938) | PT_FUNC(test_table_resize) {
function PT_FUNC (line 1959) | PT_FUNC(test_table_show) {
function PT_FUNC (line 1973) | PT_FUNC(test_table_rehash) {
function PT_SUITE (line 1997) | PT_SUITE(suite_table) {
function PT_FUNC (line 2012) | PT_FUNC(test_thread_c_int) {
function var (line 2020) | static var set_value(var args) {
function PT_FUNC (line 2025) | PT_FUNC(test_thread_call) {
function PT_FUNC (line 2039) | PT_FUNC(test_thread_cmp) {
function PT_FUNC (line 2045) | PT_FUNC(test_thread_current) {
function PT_FUNC (line 2050) | PT_FUNC(test_thread_get) {
function PT_FUNC (line 2060) | PT_FUNC(test_thread_hash) {
function PT_FUNC (line 2068) | PT_FUNC(test_thread_new) {
function PT_FUNC (line 2073) | PT_FUNC(test_thread_start) {
function cello_sleep (line 2087) | void cello_sleep(int ms) {
function var (line 2095) | static var exception_sleep(var args) {
function PT_FUNC (line 2103) | PT_FUNC(test_thread_exception) {
function PT_SUITE (line 2116) | PT_SUITE(suite_thread) {
function PT_FUNC (line 2130) | PT_FUNC(test_tree_assign) {
function PT_FUNC (line 2155) | PT_FUNC(test_tree_resize) {
function PT_FUNC (line 2172) | PT_FUNC(test_tree_cmp) {
function PT_FUNC (line 2202) | PT_FUNC(test_tree_get) {
function PT_FUNC (line 2274) | PT_FUNC(test_tree_hash) {
function PT_FUNC (line 2288) | PT_FUNC(test_tree_iter) {
function PT_FUNC (line 2308) | PT_FUNC(test_tree_len) {
function PT_FUNC (line 2320) | PT_FUNC(test_tree_new) {
function PT_FUNC (line 2366) | PT_FUNC(test_tree_show) {
function PT_SUITE (line 2380) | PT_SUITE(suite_tree) {
function PT_FUNC (line 2394) | PT_FUNC(test_tuple_assign) {
function PT_FUNC (line 2419) | PT_FUNC(test_tuple_resize) {
function PT_FUNC (line 2431) | PT_FUNC(test_tuple_cmp) {
function PT_FUNC (line 2442) | PT_FUNC(test_tuple_concat) {
function PT_FUNC (line 2457) | PT_FUNC(test_tuple_get) {
function PT_FUNC (line 2486) | PT_FUNC(test_tuple_hash) {
function PT_FUNC (line 2495) | PT_FUNC(test_tuple_iter) {
function PT_FUNC (line 2507) | PT_FUNC(test_tuple_len) {
function PT_FUNC (line 2519) | PT_FUNC(test_tuple_new) {
function PT_FUNC (line 2527) | PT_FUNC(test_tuple_push) {
function PT_FUNC (line 2549) | PT_FUNC(test_tuple_show) {
function PT_FUNC (line 2560) | PT_FUNC(test_tuple_sort) {
function PT_SUITE (line 2578) | PT_SUITE(suite_tuple) {
type TestType (line 2597) | struct TestType {
function TestType_New (line 2601) | static void TestType_New(var self, var args) {
function TestType_Cmp (line 2606) | static int TestType_Cmp(var self, var obj) {
function PT_FUNC (line 2612) | PT_FUNC(test_type_new) {
function PT_FUNC (line 2642) | PT_FUNC(test_type_c_str) {
function PT_FUNC (line 2649) | PT_FUNC(test_type_cmp) {
function PT_FUNC (line 2654) | PT_FUNC(test_type_hash) {
function PT_FUNC (line 2660) | PT_FUNC(test_type_help) {
function catch (line 2664) | catch(e) { }
function catch (line 2665) | catch(e) { }
function catch (line 2666) | catch(e) { }
function catch (line 2667) | catch(e) { }
function catch (line 2668) | catch(e) { }
function catch (line 2669) | catch(e) { }
function PT_FUNC (line 2673) | PT_FUNC(test_type_show) {
function PT_SUITE (line 2684) | PT_SUITE(suite_type) {
function PT_FUNC (line 2695) | PT_FUNC(test_zip_get) {
function PT_FUNC (line 2709) | PT_FUNC(test_zip_iter) {
function PT_FUNC (line 2734) | PT_FUNC(test_zip_len) {
function PT_FUNC (line 2748) | PT_FUNC(test_zip_new) {
function PT_SUITE (line 2762) | PT_SUITE(suite_zip) {
function exception_divide (line 2775) | static int exception_divide(int x, int y) {
function PT_FUNC (line 2784) | PT_FUNC(test_exception_throw) {
function PT_FUNC (line 2798) | PT_FUNC(test_exception_catch) {
function catch (line 2818) | catch (e) {
function PT_FUNC (line 2830) | PT_FUNC(test_exception_catch_all) {
function PT_FUNC (line 2853) | PT_FUNC(test_exception_catch_outer) {
function catch (line 2871) | catch (e) {
function PT_SUITE (line 2882) | PT_SUITE(suite_exception) {
function main (line 2891) | int main(int argc, char** argv) {
Condensed preview — 135 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (662K chars).
[
{
"path": ".gitattributes",
"chars": 11,
"preview": "text=auto\r\n"
},
{
"path": ".gitignore",
"chars": 835,
"preview": "# Main\r\n*.log\r\n*~\r\n*.libs\r\n*.o\r\n*.la\r\n*.so*\r\n*.a\r\n*.lo\r\n*.dll\r\n*.exe\r\n*.gz\r\n*.class\r\n\r\n# Tests\r\ntest.bin\r\ntest.txt\r\ntest"
},
{
"path": "LICENSE.md",
"chars": 1536,
"preview": "Licensed Under BSD\n\nCopyright (c) 2012, Daniel Holden\nAll rights reserved.\n\nRedistribution and use in source and binary "
},
{
"path": "Makefile",
"chars": 4200,
"preview": "CC ?= gcc\nAR ?= ar\n\nVERSION = 2.1.0\nPACKAGE = libCello-$(VERSION)\n\nBINDIR = ${PREFIX}/bin\nINCDIR = ${PREFIX}/include\nLIB"
},
{
"path": "README.md",
"chars": 4987,
"preview": "Cello\n=====\n\n__Cello__ is a _library_ that brings higher level programming to C.\n\nBy acting as a _modern_, _powerful_ ru"
},
{
"path": "TODO.md",
"chars": 235,
"preview": "Cello 2.0\n=========\n\nCello REPL\n==========\n\n* REPL\n - Python prototype\n - Parse CPP and extract defines.\n - Parse Syn"
},
{
"path": "benchmarks/Dict/dict_c.c",
"chars": 1093,
"preview": "#include <stdio.h>\n#include \"khash.h\"\nKHASH_MAP_INIT_STR(str, int)\n\n#define BUF_SIZE 0x10000\n#define BLOCK_SIZE 0x100000"
},
{
"path": "benchmarks/Dict/dict_cello.c",
"chars": 490,
"preview": "#include \"Cello.h\"\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nenum {\n BUF_SIZE = 0x10000\n};\n\nint main("
},
{
"path": "benchmarks/Dict/dict_cpp.cpp",
"chars": 1591,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <utility>\n#include <unordered_map>\n\nusing namespace "
},
{
"path": "benchmarks/Dict/dict_cs.cs",
"chars": 395,
"preview": "using System;\nusing System.Collections.Generic;\n\nclass dict_v1 {\n\tstatic void Main() {\n\t\tstring l;\n\t\tDictionary<string, "
},
{
"path": "benchmarks/Dict/dict_d.d",
"chars": 655,
"preview": "// This program segfaults at the end of the input file. I think this is a bug\n// of GDC. I can use std.stream or std.c.s"
},
{
"path": "benchmarks/Dict/dict_go.go",
"chars": 338,
"preview": "// Contributed by Pat\npackage main\n\nimport (\n\t\"fmt\"\n\t\"bufio\"\n\t\"os\"\n)\n\nfunc main() {\n\tr := bufio.NewReader(os.Stdin)\n\th :"
},
{
"path": "benchmarks/Dict/dict_java.java",
"chars": 546,
"preview": "import java.util.HashMap;\nimport java.io.*;\n\nclass dict_java {\n\tpublic static void main(String[] args) {\n\t\tBufferedReade"
},
{
"path": "benchmarks/Dict/dict_javascript.js",
"chars": 354,
"preview": "\n\nvar h = {}, n = 0, max = 0;\nfunction processLine (l) {\n\tif (h[l]) {\n\t\t++h[l];\n\t\tif (max < h[l]) max = h[l];\n\t} else h["
},
{
"path": "benchmarks/Dict/dict_lua.lua",
"chars": 166,
"preview": "local h, max, n = {}, 0, 0\nfor l in io.lines() do\n\tif (h[l]) then h[l] = h[l] + 1\n\telse n, h[l] = n + 1, 1 end\n\tmax = ma"
},
{
"path": "benchmarks/Dict/dict_perl.pl",
"chars": 118,
"preview": "my (%h, $max);\n\nwhile (<>) {\n next if (++$h{$_} > $max);\n $max = $h{$_};\n}\n\nprint scalar(keys(%h)), \"\\t$max\\n\";\n"
},
{
"path": "benchmarks/Dict/dict_python.py",
"chars": 235,
"preview": "import sys\n\ndef count_duplicates(lines):\n h, m = {}, 0\n for l in lines:\n if (l in h): h[l] += 1\n els"
},
{
"path": "benchmarks/Dict/dict_ruby.rb",
"chars": 140,
"preview": "h, max = {}, 0\nSTDIN.each do |l|\n\tif h[l] == nil\n\t\th[l] = 1\n\telse\n\t\th[l] = h[l] + 1\n\tend\n\tmax = h[l] if max < h[l]\nend\n#"
},
{
"path": "benchmarks/GC/gc_c.c",
"chars": 1360,
"preview": "#include <stdlib.h>\n\nstatic void create_objects(int depth) {\n \n void\n *i00=malloc(16), *i01=malloc(16), *i02=malloc(1"
},
{
"path": "benchmarks/GC/gc_cello.c",
"chars": 1266,
"preview": "#include \"Cello.h\"\n\nstatic void create_objects(int depth) {\n \n var\n i00=new(Int), i01=new(Int), i02=new(Int), i03=new"
},
{
"path": "benchmarks/GC/gc_cpp.cpp",
"chars": 1451,
"preview": "#include <stdlib.h>\n\nclass Int {\n int64_t i;\n public:\n Int() : i(0) {}\n};\n\nstatic void create_objects(int depth) {\n"
},
{
"path": "benchmarks/GC/gc_java.java",
"chars": 1311,
"preview": "public final class gc_java {\n\n final public static class Int {\n private int value;\n Int(int x) {\n va"
},
{
"path": "benchmarks/GC/gc_javascript.js",
"chars": 822,
"preview": "\nfunction Int() {\n return {val:0}\n}\n\nfunction create_objects(depth) {\n \n var i00=Int(); var i01=Int(); var i02=Int("
},
{
"path": "benchmarks/GC/gc_lua.lua",
"chars": 860,
"preview": "\nfunction Int () \n return {val=0}\nend\n\nfunction create_objects(depth)\n \n local i00=Int(); local i01=Int(); local i0"
},
{
"path": "benchmarks/GC/gc_python.py",
"chars": 617,
"preview": "\nclass Int:\n pass\n\ndef create_objects(depth):\n \n i00=Int(); i01=Int(); i02=Int(); i03=Int(); i04=Int();\n i05=I"
},
{
"path": "benchmarks/GC/gc_ruby.rb",
"chars": 690,
"preview": "\nclass Int\nend\n\ndef create_objects(depth)\n \n i00=Int.new; i01=Int.new; i02=Int.new; i03=Int.new; i04=Int.new;\n i0"
},
{
"path": "benchmarks/List/list_c.c",
"chars": 628,
"preview": "#include \"kvec.h\"\n#include <stdlib.h>\n#include <string.h>\n\nint main(int argc, char** argv) {\n \n kvec_t(int) x;\n kv_in"
},
{
"path": "benchmarks/List/list_cello.c",
"chars": 354,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n \n var x = new(Array, Int);\n \n int n = 10000;\n \n for (int i "
},
{
"path": "benchmarks/List/list_cpp.cpp",
"chars": 384,
"preview": "#include <stdlib.h>\n#include <vector>\n\nint main(int argc, char** argv) {\n \n std::vector<int> x = std::vector<int>();\n "
},
{
"path": "benchmarks/List/list_java.java",
"chars": 493,
"preview": "import java.util.ArrayList;\nimport java.util.Random;\nimport java.io.*;\n\nclass list_java {\n\tpublic static void main(Strin"
},
{
"path": "benchmarks/List/list_javascript.js",
"chars": 327,
"preview": "\nvar l = []\nvar n = 10000\n\nfor (var i = 0; i < n; i++) {\n l.push(Math.floor((Math.random() * 32767) + 0))\n}\n\nfor (var i"
},
{
"path": "benchmarks/List/list_lua.lua",
"chars": 241,
"preview": "require \"math\"\n\nl = {}\nn = 10000\n\nfor i=1,n do\n l[i] = math.random(0, 32767)\nend\n\nfor i=1,n do\n table.insert(l, \n "
},
{
"path": "benchmarks/List/list_python.py",
"chars": 279,
"preview": "import random\n\nl = []\nn = 10000\n\nrandom.seed(123)\n\nfor i in xrange(n):\n l.append(random.randint(0, 32767))\n \nfor i"
},
{
"path": "benchmarks/List/list_ruby.rb",
"chars": 131,
"preview": "\nl = []\nn = 10000\n\nn.times {\n l.push(rand())\n}\n\nn.times {\n l.insert(rand(n), rand())\n}\n \nn.times {\n l.delete_at("
},
{
"path": "benchmarks/Map/dict.lua",
"chars": 6895,
"preview": "\r\nlocal prv = {}\r\nlocal pub = {}\r\n\r\ndict = pub\r\n\r\nfunction prv.rot_less(node)\r\n\tlocal R = node.greater\r\n\tlocal M = R.les"
},
{
"path": "benchmarks/Map/map_c.c",
"chars": 1241,
"preview": "#include <stdio.h>\n#include \"kbtree.h\"\n\ntypedef struct {\n char *key;\n int count;\n} elem_t;\n\n#define elem_cmp(a, b) (st"
},
{
"path": "benchmarks/Map/map_cello.c",
"chars": 468,
"preview": "#include \"Cello.h\"\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nenum {\n BUF_SIZE = 0x10000\n};\n\nint main("
},
{
"path": "benchmarks/Map/map_cpp.cpp",
"chars": 1300,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <utility>\n#include <map>\n\nusing namespace std;\n\nstru"
},
{
"path": "benchmarks/Map/map_cs.cs",
"chars": 393,
"preview": "using System;\nusing System.Collections.Generic;\n\nclass dict_v1 {\n\tstatic void Main() {\n\t\tstring l;\n\t\tSortedSet<string, i"
},
{
"path": "benchmarks/Map/map_d.d",
"chars": 655,
"preview": "// This program segfaults at the end of the input file. I think this is a bug\n// of GDC. I can use std.stream or std.c.s"
},
{
"path": "benchmarks/Map/map_go.go",
"chars": 338,
"preview": "// Contributed by Pat\npackage main\n\nimport (\n\t\"fmt\"\n\t\"bufio\"\n\t\"os\"\n)\n\nfunc main() {\n\tr := bufio.NewReader(os.Stdin)\n\th :"
},
{
"path": "benchmarks/Map/map_java.java",
"chars": 545,
"preview": "import java.util.TreeMap;\nimport java.io.*;\n\nclass map_java {\n\tpublic static void main(String[] args) {\n\t\tBufferedReader"
},
{
"path": "benchmarks/Map/map_javascript.js",
"chars": 513,
"preview": "var RBTree = require('bintrees').RBTree;\n\nvar strcmp = function (a, b) { return a.localeCompare(b); };\n\nvar h = new RBTr"
},
{
"path": "benchmarks/Map/map_lua.lua",
"chars": 312,
"preview": "require 'Map/redblack'\n\nlocal h = redblack.newTree()\nlocal max = 0\nfor l in io.lines() do\n\tlocal c = redblack.find(h, l)"
},
{
"path": "benchmarks/Map/map_perl.pl",
"chars": 118,
"preview": "my (%h, $max);\n\nwhile (<>) {\n next if (++$h{$_} > $max);\n $max = $h{$_};\n}\n\nprint scalar(keys(%h)), \"\\t$max\\n\";\n"
},
{
"path": "benchmarks/Map/map_python.py",
"chars": 269,
"preview": "import sys\nfrom bintrees import RBTree\n\ndef count_duplicates(lines):\n h, m = RBTree(), 0\n for l in lines:\n "
},
{
"path": "benchmarks/Map/map_ruby.rb",
"chars": 164,
"preview": "require 'rbtree'\n\nh, max = RBTree[], 0\nSTDIN.each do |l|\n\tif h[l] == nil\n\t\th[l] = 1\n\telse\n\t\th[l] = h[l] + 1\n\tend\n\tmax = "
},
{
"path": "benchmarks/Map/rb.lua",
"chars": 4173,
"preview": "---------------------------------------\n--\n-- rb.lua \n-- 20110212\n--\n-- from cormen 2nd edition\n--\n------------------"
},
{
"path": "benchmarks/Map/redblack.lua",
"chars": 14745,
"preview": "--------------------------------------------------------------------------------\n-- Copyright (C) 2014, Greg Johnson.\n--"
},
{
"path": "benchmarks/Matmul/matmul_c.c",
"chars": 1291,
"preview": "// Writen by Attractive Chaos; distributed under the MIT license\n\n#include <stdlib.h>\n#include <stdio.h>\n\ndouble **mm_in"
},
{
"path": "benchmarks/Matmul/matmul_cello.c",
"chars": 1437,
"preview": "#include \"Cello.h\"\n\nstruct Matrix {\n size_t n;\n double** d;\n};\n\nstatic void Matrix_New(var self, var args) {\n struct "
},
{
"path": "benchmarks/Matmul/matmul_cpp.cpp",
"chars": 1265,
"preview": "#include <stdlib.h>\n\nclass Matrix {\n\n public:\n size_t n;\n double** d; \n\n Matrix(int n);\n ~Matrix();\n \n};\n\nMatrix:"
},
{
"path": "benchmarks/Matmul/matmul_cs.cs",
"chars": 1202,
"preview": "// Written by Attractive Chaos; distributed under the MIT license\n\n// To compile: mcs -optimize+ -out:matmul_v1.run matm"
},
{
"path": "benchmarks/Matmul/matmul_d.d",
"chars": 1063,
"preview": "// Originally written by Attractive Chaos; distributed under the MIT license (D V.2 code)\n// Contributed by leonardo and"
},
{
"path": "benchmarks/Matmul/matmul_dart.dart",
"chars": 1114,
"preview": "import 'dart:scalarlist';\n\nmat_transpose(a)\n{\n\tint m = a.length, n = a[0].length; // m rows and n cols\n\tvar b = new List"
},
{
"path": "benchmarks/Matmul/matmul_go.go",
"chars": 1028,
"preview": "// Written by Attractive Chaos; distributed under the MIT license\n\npackage main\n\nimport \"fmt\"\nimport \"flag\"\nimport \"strc"
},
{
"path": "benchmarks/Matmul/matmul_java.java",
"chars": 992,
"preview": "// Written by Attractive Chaos; distributed under the MIT license\n\nclass matmul_java {\n\tpublic double[][] matgen(int n) "
},
{
"path": "benchmarks/Matmul/matmul_javascript.js",
"chars": 979,
"preview": "// Writen by Attractive Chaos; distributed under the MIT license\n\nMath.m = {};\n\nMath.m.T = function(a) { // matrix trans"
},
{
"path": "benchmarks/Matmul/matmul_lua.lua",
"chars": 918,
"preview": "-- Writen by Attractive Chaos; distributed under the MIT license\n\nmatrix = {}\n\nfunction matrix.T(a)\n\tlocal m, n, x = #a,"
},
{
"path": "benchmarks/Matmul/matmul_perl.pl",
"chars": 1023,
"preview": "#!/usr/bin/perl -w\n\n# Writen by Attractive Chaos; distributed under the MIT license\n\nuse strict;\nuse warnings;\n\n&main;\n\n"
},
{
"path": "benchmarks/Matmul/matmul_python.py",
"chars": 844,
"preview": "import sys\n\n# Writen by Attractive Chaos; distributed under the MIT license\n\n# reference: http://www.syntagmatic.net/mat"
},
{
"path": "benchmarks/Matmul/matmul_r.R",
"chars": 692,
"preview": "matgen <- function(n) {\n\ty0 <- matrix(rep(seq(0, n-1), n), n)\n\ty1 <- t(y0)\n\tz <- 1 / n / n\n\t(y0 - y1) * (y0 + y1) * z\n}\n"
},
{
"path": "benchmarks/Matmul/matmul_ruby.rb",
"chars": 875,
"preview": "# Writen by Attractive Chaos; distributed under the MIT license\n\n# This version does not use the built-in Matrix object\n"
},
{
"path": "benchmarks/Nbodies/nbodies_c.c",
"chars": 3889,
"preview": "#include <math.h>\n#include <stdlib.h>\n\n#undef M_PI\n#define M_PI 3.14159265359\n\nstatic const double solar_mass = 4 * M_PI"
},
{
"path": "benchmarks/Nbodies/nbodies_cello.c",
"chars": 3773,
"preview": "#include \"Cello.h\"\n\nstatic const double solar_mass = 4 * M_PI * M_PI;\nstatic const double days_per_year = 365.24;\n\nstruc"
},
{
"path": "benchmarks/Nbodies/nbodies_cpp.cpp",
"chars": 3886,
"preview": "#include <vector>\n#include <cmath>\n\n#undef M_PI\n#define M_PI 3.14159265358979323846\n\nstatic const double solar_mass = 4 "
},
{
"path": "benchmarks/Nbodies/nbodies_java.java",
"chars": 4540,
"preview": "public final class nbodies_java {\n public static void main(String[] args) {\n\n NBodySystem bodies = new NBodySy"
},
{
"path": "benchmarks/Nbodies/nbodies_javascript.js",
"chars": 3662,
"preview": "\nvar pi = 3.141592653589793\nvar solar_mass = 4 * pi * pi\nvar days_per_year = 365.24\n\nvar jupiter = {\n x: 4.8414314424"
},
{
"path": "benchmarks/Nbodies/nbodies_lua.lua",
"chars": 3570,
"preview": "\nlocal pi = 3.141592653589793\nlocal solar_mass = 4 * pi * pi\nlocal days_per_year = 365.24\n\nlocal jupiter = {\n x=4.841"
},
{
"path": "benchmarks/Nbodies/nbodies_python.py",
"chars": 3488,
"preview": "import math\nimport sys\n\n# Constants\n\npi = 3.141592653589793\nsolar_mass = 4 * pi * pi\ndays_per_year = 365.24\n\n# Bodies\n\nc"
},
{
"path": "benchmarks/Nbodies/nbodies_ruby.rb",
"chars": 2657,
"preview": "SOLAR_MASS = 4 * Math::PI**2\nDAYS_PER_YEAR = 365.24\n\nclass Planet\n attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass\n\n def "
},
{
"path": "benchmarks/Sudoku/sudoku_c.c",
"chars": 8356,
"preview": "/* The MIT License\n\n Copyright (c) 2011 by Attractive Chaos <attractor@live.co.uk>\n\n Permission is hereby granted, f"
},
{
"path": "benchmarks/Sudoku/sudoku_cello.c",
"chars": 4121,
"preview": "#include \"Cello.h\"\n\nstruct Sudoku {\n uint16_t r[324][9];\n uint16_t c[729][4];\n};\n\nstatic void Sudoku_New(var self, var"
},
{
"path": "benchmarks/Sudoku/sudoku_cpp.cpp",
"chars": 8382,
"preview": "/* The MIT License\n\n Copyright (c) 2011 by Attractive Chaos <attractor@live.co.uk>\n\n Permission is hereby granted, f"
},
{
"path": "benchmarks/Sudoku/sudoku_cs.cs",
"chars": 3846,
"preview": "using System;\n\nclass sudoku_v1 {\n\tint[,] R, C;\n\tpublic void genmat() {\n\t\tR = new int[324,9];\n\t\tC = new int[729,4];\n\t\tint"
},
{
"path": "benchmarks/Sudoku/sudoku_d.d",
"chars": 7050,
"preview": "// Works with LDC1\n// Compile with: ldc -O3 -release -inline\n// Contributed by leonardo\n\n/*\nThe MIT License\n\nCopyright ("
},
{
"path": "benchmarks/Sudoku/sudoku_dart.dart",
"chars": 3354,
"preview": "import 'dart:core';\nimport 'dart:io';\nimport 'dart:typeddata';\n\nclass Sudoku {\n final _R = new List<Uint16List>(324);\n "
},
{
"path": "benchmarks/Sudoku/sudoku_go.go",
"chars": 3028,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\ntype sdaux_t struct {\n\tr [324][9]uint16\n\tc [729][4]uint16\n}\n\nfunc sd_gen"
},
{
"path": "benchmarks/Sudoku/sudoku_java.java",
"chars": 4017,
"preview": "import java.io.*;\n\nclass sudoku_java {\n\tint[][] R, C;\n\tpublic void genmat() {\n\t\tR = new int[324][9];\n\t\tC = new int[729]["
},
{
"path": "benchmarks/Sudoku/sudoku_javascript.js",
"chars": 2875,
"preview": "function Sudoku() {\n\tvar C = [], R = [];\n\t\n\tfunction sd_genmat() { // precompute matrix\n\t\tvar i, j, r, c, c2;\n\t\tfor (i ="
},
{
"path": "benchmarks/Sudoku/sudoku_lua.lua",
"chars": 2574,
"preview": "function sd_genmat()\n\tlocal R, C, r = {}, {}, 0\n\tfor i = 0, 8 do\n\t\tfor j = 0, 8 do\n\t\t\tfor k = 0, 8 do\n\t\t\t\tC[r], r = { 9 "
},
{
"path": "benchmarks/Sudoku/sudoku_perl.pl",
"chars": 2514,
"preview": "use strict;\nuse warnings;\n\nmy @aux = &sd_genmat();\nwhile (<>) {\n\tchomp;\n\tif (length($_) >= 81) {\n\t\tmy $ret = &sd_solve($"
},
{
"path": "benchmarks/Sudoku/sudoku_python.py",
"chars": 1918,
"preview": "import sys, string\n\ntry:\n\txrange(1)\nexcept NameError:\n\txrange = range\n\ndef sd_genmat():\n\tC = [[n/9, n/81*9 + n%9 + 81, n"
},
{
"path": "benchmarks/Sudoku/sudoku_ruby.rb",
"chars": 2573,
"preview": "def sd_genmat()\n\tmr = Array.new(324) { [] }\n\tmc = Array.new(729) { [] }\n\tr = 0\n\t(0...9).each do |i|\n\t\t(0...9).each do |j"
},
{
"path": "benchmarks/benchmark",
"chars": 6989,
"preview": "gcc ./ext/genint.c -o ./ext/genint\n\ngcc Nbodies/nbodies_c.c -std=c99 -O3 -lm -o Nbodies/nbodies_c\ng++ Nbodies/nbodies_cp"
},
{
"path": "benchmarks/benchmark.sh",
"chars": 7520,
"preview": "#!/bin/sh\ngcc ./ext/genint.c -o ./ext/genint\n\ngcc Nbodies/nbodies_c.c -std=c99 -O3 -lm -o Nbodies/nbodies_c\ng++ Nbodies/"
},
{
"path": "benchmarks/ext/cleantxt.c",
"chars": 529,
"preview": "#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n\nint main(int argc, char *argv[])\n{\n\tFILE *fp;\n\tint c = EOF;\n\t"
},
{
"path": "benchmarks/ext/genint.c",
"chars": 416,
"preview": "/* This program generates 5 million recurrent integers. Each distinct integer\n * occurs 4 times in average.\n */\n#include"
},
{
"path": "benchmarks/ext/kbtree.h",
"chars": 15819,
"preview": "/*-\n * Copyright 1997-1999, 2001, John-Mark Gurney.\n * 2008-2009, Attractive Chaos <attractor@live.co.uk>\n *\n "
},
{
"path": "benchmarks/ext/khash.h",
"chars": 17815,
"preview": "/* The MIT License\n\n Copyright (c) 2008, 2009, 2011 by Attractive Chaos <attractor@live.co.uk>\n\n Permission is hereb"
},
{
"path": "benchmarks/ext/kvec.h",
"chars": 2881,
"preview": "/* The MIT License\n\n Copyright (c) 2008, by Attractive Chaos <attractor@live.co.uk>\n\n Permission is hereby granted, "
},
{
"path": "benchmarks/ext/regexp9.c",
"chars": 27502,
"preview": "/*\n Copyright information from the original package:\n*/\n/*\n The authors of this software is Rob Pike.\n\t\tCopyright (c) "
},
{
"path": "benchmarks/ext/regexp9.h",
"chars": 3875,
"preview": "#ifndef _REGEXP9_H_\n#define _REGEXP9_H_ 1\n\n/*********\n * utf.h *\n *********/\n\ntypedef unsigned short Rune;\n\ntypedef stru"
},
{
"path": "benchmarks/ext/sudoku",
"chars": 21,
"preview": "cat ./ext/sudoku.txt\n"
},
{
"path": "benchmarks/ext/sudoku.txt",
"chars": 19990,
"preview": "..............3.85..1.2.......5.7.....4...1...9.......5......73..2.1........4...9\tnear worst case for brute-force solver"
},
{
"path": "benchmarks/graphs.py",
"chars": 2204,
"preview": "import numpy as np\nfrom matplotlib import pyplot as plt\n\nlanguages = np.array([\n 'C', 'C++', 'Cello', \n 'Java', 'J"
},
{
"path": "examples/cello_world.c",
"chars": 95,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n println(\"Cello World!\");\n return 0;\n}\n"
},
{
"path": "examples/help.c",
"chars": 90,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n \n help(Range);\n \n return 0;\n}\n\n"
},
{
"path": "examples/iteration.c",
"chars": 411,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n\n /* Stack objects are created using \"$\" */\n var i0 = $(Int, 5);"
},
{
"path": "examples/newtype.c",
"chars": 1257,
"preview": "#include \"Cello.h\"\n\n/* Type Variable */\nstatic var ExampleType;\n\n/* Type Struct */\nstruct ExampleType {\n int value;\n};\n"
},
{
"path": "examples/object.c",
"chars": 629,
"preview": "#include \"Cello.h\"\n\n/* Define a normal C structure */\nstruct Point {\n float x, y;\n};\n\n/* Make it compatible with Cello "
},
{
"path": "examples/ranges.c",
"chars": 446,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n\n var items = new(Array, Int, \n $I( 8), $I( 5), $I(20), \n $"
},
{
"path": "examples/table.c",
"chars": 419,
"preview": "#include \"Cello.h\"\n\nint main(int argc, char** argv) {\n\n /* Shorthand $ can be used for basic types */\n var prices = ne"
},
{
"path": "examples/threads.c",
"chars": 665,
"preview": "#include \"Cello.h\"\n\n/* Threaded Callback */\nvar say_hello(var args) {\n with (mutex in get(args, $I(0))) {\n println(\""
},
{
"path": "include/Cello.h",
"chars": 16956,
"preview": "/*\n** $$===================================================$$\n** || "
},
{
"path": "src/Alloc.c",
"chars": 12243,
"preview": "#include \"Cello.h\"\n\nstruct Header* header(var self) {\n return (struct Header*)((char*)self - sizeof(struct Header));\n}\n"
},
{
"path": "src/Array.c",
"chars": 12668,
"preview": "#include \"Cello.h\"\n\nstatic const char* Array_Name(void) {\n return \"Array\";\n}\n\nstatic const char* Array_Brief(void) {\n "
},
{
"path": "src/Assign.c",
"chars": 4472,
"preview": "#include \"Cello.h\"\n\nstatic const char* Assign_Name(void) {\n return \"Assign\";\n}\n\nstatic const char* Assign_Brief(void) {"
},
{
"path": "src/Cmp.c",
"chars": 6055,
"preview": "#include \"Cello.h\"\n\nstatic const char* Cmp_Name(void) {\n return \"Cmp\";\n}\n\nstatic const char* Cmp_Brief(void) {\n return"
},
{
"path": "src/Concat.c",
"chars": 1851,
"preview": "#include \"Cello.h\"\n\nstatic const char* Concat_Name(void) {\n return \"Concat\";\n}\n\nstatic const char* Concat_Brief(void) {"
},
{
"path": "src/Doc.c",
"chars": 4038,
"preview": "#include \"Cello.h\"\n\nstatic const char* Doc_Name(void) {\n return \"Doc\";\n}\n\nstatic const char* Doc_Brief(void) {\n return"
},
{
"path": "src/Exception.c",
"chars": 11786,
"preview": "#include \"Cello.h\"\n\n#define EXCEPTION_TLS_KEY \"__Exception\"\n\nenum {\n EXCEPTION_MAX_DEPTH = 2048,\n EXCEPTION_MAX_STRAC"
},
{
"path": "src/File.c",
"chars": 12606,
"preview": "#include \"Cello.h\"\n\nstatic const char* Stream_Name(void) {\n return \"Stream\";\n}\n\nstatic const char* Stream_Brief(void) {"
},
{
"path": "src/Function.c",
"chars": 3352,
"preview": "#include \"Cello.h\"\n\nstatic const char* Call_Name(void) {\n return \"Call\";\n}\n\nstatic const char* Call_Brief(void) {\n ret"
},
{
"path": "src/GC.c",
"chars": 13351,
"preview": "#include \"Cello.h\"\n\nstatic const char* Mark_Name(void) {\n return \"Mark\";\n}\n\nstatic const char* Mark_Brief(void) {\n ret"
},
{
"path": "src/Get.c",
"chars": 3156,
"preview": "#include \"Cello.h\"\n\nstatic const char* Get_Name(void) {\n return \"Get\";\n}\n\nstatic const char* Get_Brief(void) {\n return"
},
{
"path": "src/Hash.c",
"chars": 3266,
"preview": "#include \"Cello.h\"\n\nstatic const char* Hash_Name(void) {\n return \"Hash\";\n}\n\nstatic const char* Hash_Brief(void) {\n ret"
},
{
"path": "src/Iter.c",
"chars": 29554,
"preview": "#include \"Cello.h\"\n\nvar _ = CelloEmpty(_);\nvar Terminal = CelloEmpty(Terminal);\n\nstatic const char* Iter_Name(void) {\n "
},
{
"path": "src/Len.c",
"chars": 1315,
"preview": "#include \"Cello.h\"\n\nstatic const char* Len_Name(void) {\n return \"Len\";\n}\n\nstatic const char* Len_Brief(void) {\n return"
},
{
"path": "src/List.c",
"chars": 10342,
"preview": "#include \"Cello.h\"\n\nstatic const char* List_Name(void) {\n return \"List\";\n}\n\nstatic const char* List_Brief(void) {\n ret"
},
{
"path": "src/Num.c",
"chars": 5840,
"preview": "#include \"Cello.h\"\n\nstatic const char* C_Int_Name(void) {\n return \"C_Int\";\n}\n\nstatic const char* C_Int_Brief(void) {\n "
},
{
"path": "src/Pointer.c",
"chars": 6728,
"preview": "#include \"Cello.h\"\n\nstatic const char* Pointer_Name(void) {\n return \"Pointer\";\n}\n\nstatic const char* Pointer_Brief(void"
},
{
"path": "src/Push.c",
"chars": 2337,
"preview": "#include \"Cello.h\"\n\nstatic const char* Push_Name(void) {\n return \"Push\";\n}\n\nstatic const char* Push_Brief(void) {\n ret"
},
{
"path": "src/Resize.c",
"chars": 1802,
"preview": "#include \"Cello.h\" \n\nstatic const char* Resize_Name(void) {\n return \"Reserve\";\n}\n\nstatic const char* Resize_Brief(void)"
},
{
"path": "src/Show.c",
"chars": 13728,
"preview": "#include \"Cello.h\"\n\nstatic const char* Format_Name(void) {\n return \"Format\";\n}\n\nstatic const char* Format_Brief(void) {"
},
{
"path": "src/Start.c",
"chars": 2663,
"preview": "#include \"Cello.h\"\n\nstatic const char* Start_Name(void) {\n return \"Start\";\n}\n\nstatic const char* Start_Brief(void) {\n "
},
{
"path": "src/String.c",
"chars": 11309,
"preview": "#include \"Cello.h\"\n\nstatic const char* C_Str_Name(void) {\n return \"C_Str\";\n}\n\nstatic const char* C_Str_Brief(void) {\n "
},
{
"path": "src/Table.c",
"chars": 17177,
"preview": "#include \"Cello.h\"\n\nstatic const char* Table_Name(void) {\n return \"Table\";\n}\n\nstatic const char* Table_Brief(void) {\n "
},
{
"path": "src/Thread.c",
"chars": 15035,
"preview": "#include \"Cello.h\"\n\nstatic const char* Current_Name(void) {\n return \"Current\";\n}\n\nstatic const char* Current_Brief(void"
},
{
"path": "src/Tree.c",
"chars": 19977,
"preview": "#include \"Cello.h\"\n\nstatic const char* Tree_Name(void) {\n return \"Tree\";\n}\n\nstatic const char* Tree_Brief(void) {\n ret"
},
{
"path": "src/Tuple.c",
"chars": 12348,
"preview": "#include \"Cello.h\"\n\nstatic const char* Tuple_Name(void) {\n return \"Tuple\";\n}\n\nstatic const char* Tuple_Brief(void) {\n "
},
{
"path": "src/Type.c",
"chars": 15794,
"preview": "#include \"Cello.h\"\n\nstatic const char* Cast_Name(void) {\n return \"Cast\";\n}\n\nstatic const char* Cast_Brief(void) {\n ret"
},
{
"path": "tests/ptest.c",
"chars": 7617,
"preview": "#include \"ptest.h\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <time.h>\n#if defined(CELLO_UNIX)"
},
{
"path": "tests/ptest.h",
"chars": 741,
"preview": "#ifndef ptest_h\n#define ptest_h\n\n#include <string.h>\n\n#define PT_SUITE(name) void name(void)\n\n#define PT_FUNC(name) stat"
},
{
"path": "tests/test.c",
"chars": 58210,
"preview": "#include \"../include/Cello.h\"\n#include \"ptest.h\"\n\n/* Array */\n\nPT_FUNC(test_array_new) {\n \n var a0 = new(Array, Int, $"
}
]
About this extraction
This page contains the full source code of the orangeduck/Cello GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 135 files (593.7 KB), approximately 207.0k tokens, and a symbol index with 1165 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.