initial commit

This commit is contained in:
Jarrad Hope 2015-07-03 11:32:09 +02:00
commit fdbd7c059c
4 changed files with 101 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.DS_Store
rlp
ethereum

61
contracts/minheap.se Normal file
View File

@ -0,0 +1,61 @@
# Min Heap
# bids and asks
# with price, amount and trader encoded in a single 256 bit value
data heap[2**256]
def push(item):
length = heap[0]
k = length + 1
heap[k] = item
log(k)
while k > 1:
log(666)
bottom = heap[k]
top = heap[k/2]
log(top)
log(bottom)
if bottom < top:
heap[k] = top
heap[k/2] = bottom
k /= 2
else:
k = 0
log(k)
heap[0] = k
def pop():
length = heap[0]
if !length:
return(0)
prevtop = heap[1]
heap[1] = heap[length]
heap[length] = 0
top = heap[1]
k = 1
while k * 2 < length:
bottom1 = heap[k * 2]
bottom2 = heap[k * 2 + 1]
if bottom1 < top and (bottom1 < bottom2 or k * 2 + 1 >= length):
heap[k] = bottom1
heap[k * 2] = top
k = k * 2
elif bottom2 < top and bottom2 < bottom1 and k * 2 + 1 < length:
heap[k] = bottom2
heap[k * 2 + 1] = top
k = k * 2 + 1
else:
k = length
heap[0] = length - 1
return(prevtop)
def top():
return(heap[1])
def length():
return(heap[0])

10
contracts/xorlist.se Normal file
View File

@ -0,0 +1,10 @@
# XOR List
# For Trade Keys, points to hashmap for trade data
# http://www.geeksforgeeks.org/xor-linked-list-a-memory-efficient-doubly-linked-list-set-2/
data xorlist[](key)
data hashmap[](value)
def xoritem():
return("monkey" xor "chowder")

27
test.py Normal file
View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from ethereum import tester, slogging
state = tester.state()
def listener(msg):
if msg['event'] == 'LOG':
print(msg)
slogging.log_listeners.listeners.append(listener)
with open('contracts/minheap.se') as fh:
minheap_se = fh.read()
with open('contracts/xorlist.se') as fh:
xorlist_se = fh.read()
minheap = state.abi_contract(minheap_se)
xorlist = state.abi_contract(xorlist_se)
minheap.push(5)
minheap.push(10)
# minheap.pop()
print(minheap.top())