Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.59 KB | None | 0 0
  1. ## SlotMap
  2. type
  3.   Slot*[T] = object
  4.     slotMap: SlotMap
  5.     index: int
  6.  
  7.   SlotMap*[T] = ref object
  8.     perChunk: int
  9.     chunks: seq[pointer]
  10.  
  11. proc newSlotMap*[T](perChunk: int): SlotMap[T] =
  12.   new(result)
  13.   result.chunks = @[]
  14.   result.perChunk = perChunk
  15.  
  16. proc add*[T](slotMap: SlotMap[T], item: T): Slot[T] =
  17.   Slot[T](slotMap: slotMap, index: 0) #TODO: allocate in chunk, return allocated index
  18.  
  19.  
  20. ## tests
  21. when isMainModule:
  22.   type
  23.     Component = object
  24.  
  25.  
  26.   var sm = newSlotMap[Component](128)
  27.   echo $sm.perChunk
  28.  
  29.   var obj = sm.add(Component())
  30.   echo $obj.index
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement