Copyright | (c) CindyLinz 2016 |
---|---|
License | MIT |
Maintainer | cindylinz@gmail.com |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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.
- class IterLinkedList iter where
- data LinkedList iter value
- firstIter :: LinkedList iter value -> iter
- lastIter :: LinkedList iter value -> iter
Documentation
class IterLinkedList iter where #
Polymorphic operations on the list
Minimal complete definition
null, get, (set | modify), next, prev, empty, singleton, insertBefore, insertAfter, delete, toList
Methods
null :: LinkedList iter value -> Bool #
See if this list is an empty list. O(1)
get :: iter -> LinkedList iter value -> Maybe value #
Get the element value. O(lg N)
get' :: iter -> LinkedList iter value -> value #
Get the element value. Get undefined if not found. O(lg N)
set :: iter -> value -> LinkedList iter value -> LinkedList iter value #
Set the element value.
Return the original list if the iterator is not in the list O(lg N)
modify :: iter -> (value -> value) -> LinkedList iter value -> LinkedList iter value #
Modify the element value.
Return the original list if the iterator is not in the list O(lg N)
next :: LinkedList iter value -> iter -> iter #
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 #
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 #
Get an empty list. O(1)
singleton :: value -> LinkedList iter value #
Get a list with exactly one element. O(1)
insertBefore :: iter -> value -> LinkedList iter value -> LinkedList iter value #
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 #
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 #
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 #
Get a LinkedList from a list
O(N)
toList :: LinkedList iter value -> [value] #
Get a list from a LinkedList
O(N lg N)
Instances
data LinkedList iter value #
The list
Instances
Show value => Show (LinkedList Int value) # | |
Show value => Show (LinkedList Integer value) # | |
firstIter :: LinkedList iter value -> iter #
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 #
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)