Skip to content

Instantly share code, notes, and snippets.

@mmitou
mmitou / binary-heap.hs
Created December 17, 2011 02:16
関数プログラミングの楽しみ 1章 binary heap
-- 関数プログラミングの楽しみ 第1章
data (Ord a) => Tree a = Null | Fork a (Tree a) (Tree a)
deriving (Show, Eq)
isEmpty :: Tree a -> Bool
isEmpty Null = True
isEmpty x = False
minElem :: Ord a => Tree a -> a
@mmitou
mmitou / redBlackTree.hs
Created December 17, 2011 02:26
pfds 3章 赤黒木
data Color = R | B deriving(Show, Eq)
data Ord a => RedBlackSet a = E | T Color (RedBlackSet a) a (RedBlackSet a)
deriving (Show, Eq)
member :: Ord a => a -> RedBlackSet a -> Bool
member x E = False
member x (T _ a y b) | x < y = member x a
| x > y = member x b
| otherwise = True
@mmitou
mmitou / 12.hs
Created December 31, 2011 00:51
プログラミングHaskell 12章
{--
12.1
1 + (2*3) の簡約可能式は
最も外側のものが 1+(2*3)
最も内側のものが (2*3)
(1+2)*(2+3)の簡約可能式は
最も外側のものが (1+2)*(2+3)
最も内側のものが (1+2)と(2+3)の両方
@mmitou
mmitou / SplayHeap.hs
Created January 15, 2012 16:18
SplayHeap
data SplayHeap a = E | T (SplayHeap a) a (SplayHeap a) deriving(Show)
partition pivot E = (E, E)
partition pivot t@(T a x b) =
if x <= pivot then
case b of
E -> (t, E)
T b1 y b2 -> if y <= pivot then
let (small, big) = partition pivot b2
in (T (T a x b) y small, big)
@mmitou
mmitou / kstring.h
Created January 30, 2012 17:40
簡易版sprintf
#include "kstring.h"
#include <stdio.h>
static const int MAXDIGITS = 20;
static const char char_table[16]
= {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
int int2str(const int n, const int x, char *str)
{
@mmitou
mmitou / Function.hpp
Created February 24, 2012 17:18
オブジェクトとメソッドを一纏めにして呼び出せるようにしたもの。
#ifndef __MY_FUNCTION_HPP__
#define __MY_FUNCTION_HPP__
#include <boost/shared_ptr.hpp>
struct Holder
{
virtual ~Holder(){};
};
@mmitou
mmitou / SharedPointer
Created February 26, 2012 13:33
簡易版SharedPointer
#ifndef __SHAREDPOINTER_HPP__
#define __SHAREDPOINTER_HPP__
template <class T>
class SharedPointer
{
public:
template <class U>
SharedPointer(U *obj)
{
@mmitou
mmitou / Makefile
Created June 26, 2012 17:13
list_head sample
obj-m := listtest.o
INC := /usr/src/kernels/3.4.0-1.fc17.x86_64/include
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
check-syntax:
@mmitou
mmitou / Makefile
Created August 23, 2012 06:21
exeve観察用stp
.PHONY: all
all: exec test
exec: exec.c
gcc exec.c -o exec
test: test.c
gcc test.c -o test
probe kernel.function("sys_execve") {
printf("%s -> %s\n", thread_indent(1), probefunc());
printf("%s name = %s\n", thread_indent(0), kernel_string($name));
printf("%s argv[0] = %s\n", thread_indent(0), kernel_string($argv[0]));
printf("%s envp[0] = %s\n", thread_indent(0), kernel_string($envp[0]));
printf("%s envp[1] = %s\n", thread_indent(0), kernel_string($envp[1]));
}
probe kernel.function("do_execve") {
printf("%s -> %s\n", thread_indent(1), probefunc());