linked-list-with-iterator-0.1.0.0: A pure linked list which is mutable through iterators.

Copyright(c) CindyLinz, 2016
LicenseMIT
Maintainercindylinz@gmail.com
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.IterLinkedList

Description

A pure linked list with is mutable through iterators.

It's iternally implemented by IntMap or Map Integer, using Int or Integer as the iterator type respectly. Most of the operations cost O(lg N). Each newly inserted element will consume a unique number and never reuse old numbers. Choose Int one if you're sure that there're no more than Int space times of insertions, or choose Integer one otherwise.

Synopsis

Documentation

class Enum iter => IterLinkedList iter where Source #

Polymorphic operations on the list

Methods

null :: LinkedList iter value -> Bool Source #

See if this list is an empty list. O(1)

get :: iter -> LinkedList iter value -> Maybe value Source #

Get the element value. O(lg N)

get' :: iter -> LinkedList iter value -> value Source #

Get the element value. Get undefined if not found. O(lg N)

next :: LinkedList iter value -> iter -> iter Source #

Get the next iterator. If the specified iterator is the last one, or isn't in the list, return the original one. O(lg N)

prev :: LinkedList iter value -> iter -> iter Source #

Get the previous iterator. If the specified iterator is the first one, or isn't in the list, return the original one. O(lg N)

empty :: LinkedList iter value Source #

Get an empty list. O(1)

singleton :: value -> LinkedList iter value Source #

Get a list with exactly one element. O(1)

insertBefore :: iter -> value -> LinkedList iter value -> LinkedList iter value Source #

Insert a new element before the specified iterator. If the list is empty, just insert the new element as the only element. If the specified iterator can't be found, prepend the new element to the whole list. O(lg N)

insertAfter :: iter -> value -> LinkedList iter value -> LinkedList iter value Source #

Insert a new element after the specified iterator. If the list is empty, just insert the new element as the only element. If the specified iterator can't be found, append the new element to the whole list. O(lg N)

delete :: iter -> LinkedList iter value -> LinkedList iter value Source #

Delete the specified element from the list. If there's no such element in the list, return the original list. O(lg N)

fromList :: [value] -> LinkedList iter value Source #

Get a LinkedList from a list O(N)

toList :: LinkedList iter value -> [value] Source #

Get a list from a LinkedList O(N lg N)

Instances

IterLinkedList Int Source # 

Methods

null :: LinkedList Int value -> Bool Source #

get :: Int -> LinkedList Int value -> Maybe value Source #

get' :: Int -> LinkedList Int value -> value Source #

next :: LinkedList Int value -> Int -> Int Source #

prev :: LinkedList Int value -> Int -> Int Source #

empty :: LinkedList Int value Source #

singleton :: value -> LinkedList Int value Source #

insertBefore :: Int -> value -> LinkedList Int value -> LinkedList Int value Source #

insertAfter :: Int -> value -> LinkedList Int value -> LinkedList Int value Source #

delete :: Int -> LinkedList Int value -> LinkedList Int value Source #

fromList :: [value] -> LinkedList Int value Source #

toList :: LinkedList Int value -> [value] Source #

IterLinkedList Integer Source # 

data LinkedList iter value Source #

The list

Instances

Show value => Show (LinkedList Int value) Source # 

Methods

showsPrec :: Int -> LinkedList Int value -> ShowS #

show :: LinkedList Int value -> String #

showList :: [LinkedList Int value] -> ShowS #

Show value => Show (LinkedList Integer value) Source # 

firstIter :: LinkedList iter value -> iter Source #

Get the first iterator. If the list is empty, you'll still get an unusable one. You can't get the value from the unusable iterator. O(lg N)

lastIter :: LinkedList iter value -> iter Source #

Get the last iterator. If the list is empty, you'll still get an unusable one. You can't get the value from the unusable iterator. O(lg N)