tskiplist-1.0.1: A Skip List Implementation in Software Transactional Memory (STM)

CopyrightPeter Robinson 2010-2013
LicenseLGPL
MaintainerPeter Robinson <thaldyron@gmail.com>
Stabilityexperimental
Portabilitynon-portable (requires STM)
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.STM.TSkipList.Internal

Contents

Description

 
Synopsis

Data types and Construction

data TSkipList k a Source #

A skip list data type.

Constructors

TSkipList 

Fields

newIO :: IO (TSkipList k a) Source #

Creates a skiplist. Default values for storing up to 2^16 elements.

newIO' Source #

Arguments

:: Float

Probability for choosing a new level

-> Int

Maximum number of levels.

-> IO (TSkipList k a) 

Creates a skiplist.

new :: STM (TSkipList k a) Source #

Creates a skiplist. Default values for storing up to 2^16 elements.

new' Source #

Arguments

:: Float

Probability for choosing a new level

-> Int

Maximum number of levels

-> STM (TSkipList k a) 

Creates a skiplist.

data Traversal k a b Source #

Traversal strategy.

Constructors

Traversal 

Fields

type ForwardPtrs k a = TArray Int (Node k a) Source #

data Node k a Source #

An entry of the skip list.

Constructors

Nil 
Node 

Fields

Operations

insert :: Ord k => k -> a -> TSkipList k a -> STM () Source #

Insertsupdates the value for a specific key. O(log n)/.

lookup :: Ord k => k -> TSkipList k a -> STM (Maybe a) Source #

Searches for a given entry. O(log n).

update :: Ord k => k -> a -> TSkipList k a -> STM () Source #

Updates an element. Throws AssertionFailed if the element is not in the list. O(log n).

delete :: Ord k => k -> TSkipList k a -> STM () Source #

Deletes an element. Does nothing if the element is not found. O(log n).

filter :: Ord k => (k -> Bool) -> TSkipList k a -> STM (Map k a) Source #

Returns all elements that satisfy the predicate on keys. O(n).

filterGT :: Ord k => k -> TSkipList k a -> STM (Map k a) Source #

Returns all elements greater than the key. TODO: currently in O(n), should be made more efficient (like leq)

filterLT :: Ord k => k -> TSkipList k a -> STM (Map k a) Source #

Returns all elements less than the key. Takes O(m) where m is the number of elements that have a smaller key.

filterElems :: Ord k => (k -> a -> Bool) -> TSkipList k a -> STM (Map k a) Source #

Returns all elements that satisfy the predicate on keys and values. O(n).

minimum :: Ord k => TSkipList k a -> STM (k, a) Source #

Returns the minimum entry. O(1).

maximum :: Ord k => TSkipList k a -> STM (k, a) Source #

Returns the maximum entry. O(log n).

filterRange :: Ord k => (k, k) -> TSkipList k a -> STM [(k, a)] Source #

Finds all elements within a specific key range (k1,k2). O(log n + k2 - k1).

Low-level Operations

traverseSL Source #

Arguments

:: Ord k 
=> k

search key

-> ForwardPtrs k a

forward pointers to the next node

-> Int

current level

-> Traversal k a b

traversal strategy

-> b

default value

-> STM b 

lookupNode :: Ord k => k -> TSkipList k a -> STM (Maybe (Node k a)) Source #

insertNode :: Ord k => k -> Node k a -> TSkipList k a -> STM () Source #

Utilities

chooseLevel :: TSkipList k a -> Int Source #

Returns a randomly chosen level. Used for inserting new elements. O(1). For performance reasons, this function uses unsafePerformIO to access the random number generator. (It would be possible to store the random number generator in a TVar and thus be able to access it safely from within the STM monad. This, however, might cause high contention among threads.)

toString :: (Show k, Ord k) => TSkipList k a -> STM String Source #

Returns the skip list as a string.