less expensive xorll addr

This commit is contained in:
Jarrad Hope 2015-07-18 23:06:17 +02:00
parent d64a8ae28e
commit 0154c4addd
3 changed files with 18 additions and 10 deletions

View File

@ -23,8 +23,9 @@ data ticket # auto increment
def init():
ticket = 0
offer = 0
self.ticket = 0
self.offer = 0
self.xorll_addr = 1 # referenced in xorll.se, can't be 0
def shared():
@ -44,11 +45,14 @@ def add():
# Preferences
# Head pointer
# TODO: Maybe insert returns np and key, maybe also use autoincrement
# TODO: Make SHA3 happen in insert, save label, maybe can use autoincrement for pointers instead of hash?
head = self.insert(sha3(ticket + "head"), 10+ticket, 0, 0)
# TODO: remove head tail xorll preamble
# TODO: store tail_np, then if self.pool[ticket].preferences.head == 0
# in insert method, take tail_np and head, then set as head.
# then do tail on next insert.
head = self.insert("head", 10+ticket, 0, 0)
self.pool[ticket].preferences.head = head
# Tail pointer
self.pool[ticket].preferences.tail = self.insert(sha3(ticket + "tail"), 20, 0, head)
self.pool[ticket].preferences.tail = self.insert("tail", 20, 0, head)
# TODO: insurance references
return(ticket)
@ -59,7 +63,7 @@ def add_preference(ticket, key, value):
tail = self.pool[ticket].preferences.tail
# or make tail() return np in insert as well?
tail_np = self.np(tail)
tail = self.insert(sha3(ticket + key), value, tail_np, tail)
tail = self.insert(key, value, tail_np, tail)
self.pool[ticket].preferences.tail = tail

View File

@ -1,7 +1,8 @@
# XOR Linked List
# For Trade Keys, points to hashmap for trade data
data xorll[](value, np) # np = next xor previous
data xorll[](key, value, np) # np = next xor previous
data xorll_addr
# traverse the list given either the head or the tail
@ -10,7 +11,7 @@ def traverse(start): # pointer to head or tail
prev = start
while self.xorll[cur].value:
log(self.xorll[cur].value)
log(self.xorll[cur].key, self.xorll[cur].value)
if self.xorll[cur].np == cur:
# finished
@ -24,10 +25,13 @@ def traverse(start): # pointer to head or tail
prev = tmp
def insert(pointer, value, prev, cur):
def insert(key, value, prev, cur):
# if self.xorll[pointer].value != 0:
# stop
pointer = self.xorll_addr
self.xorll_addr = self.xorll_addr + 1
self.xorll[pointer].key = key
self.xorll[pointer].value = value
self.xorll[pointer].np = cur # end node points to previous one

View File

@ -31,7 +31,7 @@ market.activate(buy_ticket)
# Create sell ticket, add preferences, activate
sell_ticket = market.add()
print('sell_ticket', sell_ticket)
market.add_preference(sell_ticket, 'price', '-7') # TODO: handle negative numbers
market.add_preference(sell_ticket, 'price', '-7') # TODO: handle negative numbers
market.activate(sell_ticket)
# print('reveal', market.add_sealed_offer(0, 1))