template rightSize(cap): untyped {.dirty.}=
      when declared(tables.rightSize)and(NimMajor,NimMinor)<(1,4):
        tables.rightSize(cap)
      else:
        cap
    
    proc newLruCache*[K,T](capacity: int): LruCache[K,T] =
      ## Create a new Least-Recently-Used (LRU) cache that store the last 
`capacity`-accessed items.
      LruCache[K,T](
        capacity: capacity,
        list: initDoublyLinkedList[Node[K,T]](),
        table: initTable[K, DoublyLinkedNode[Node[K,T]]]( rightSize(capacity) )
        )
    
    
    Run

Reply via email to