Safe Haskell | None |
---|
CircularList
Description
A CircularList that uses a linked list based on Data.Vector.
Here are a couple of working/design assumptions ...
- the inital list is consecutive, means it contains the numbers from 1 to N in a/the given order. And the smallest element is 1.
- the linked-list will always have one element it: (0,0). With this element in it the CircularList is considered empty. We need this element because Vector is to the base of 0 and our lists are starting with 1.
- to remove an element from the list the predecessor and the successor need to be re-linked. The element it-self will be marked as deleted by making it point to 0.
- we will never addinsert an elementitem that is bigger than N.
Synopsis
- data AlreadyExistsException = AlreadyExistsException
- data ItemNotFoundException = ItemNotFoundException
- data ListIsEmptyException = ListIsEmptyException
- data OutOfRangeException = OutOfRangeException
- data StackIsEmptyException = StackIsEmptyException
- type Current = Int
- type Item = Int
- data CircularList = CircularList Current (Vector Item) [Current]
- fromList :: Int -> [Int] -> CircularList
- toList :: CircularList -> [Int]
- size :: CircularList -> Int
- allocated :: CircularList -> Int
- isEmpty :: CircularList -> Bool
- isIn :: Int -> CircularList -> Bool
- get :: CircularList -> Item
- forward :: CircularList -> CircularList
- insert :: Int -> CircularList -> CircularList
- remove :: CircularList -> CircularList
- move :: Int -> CircularList -> CircularList
- push :: CircularList -> CircularList
- pop :: CircularList -> CircularList
Documentation
data AlreadyExistsException #
Constructors
AlreadyExistsException |
Instances
Eq AlreadyExistsException # | |
Defined in CircularList Methods (==) :: AlreadyExistsException -> AlreadyExistsException -> Bool (/=) :: AlreadyExistsException -> AlreadyExistsException -> Bool | |
Show AlreadyExistsException # | |
Defined in CircularList Methods showsPrec :: Int -> AlreadyExistsException -> ShowS show :: AlreadyExistsException -> String showList :: [AlreadyExistsException] -> ShowS | |
Exception AlreadyExistsException # | |
Defined in CircularList Methods toException :: AlreadyExistsException -> SomeException fromException :: SomeException -> Maybe AlreadyExistsException displayException :: AlreadyExistsException -> String |
data ItemNotFoundException #
Constructors
ItemNotFoundException |
Instances
Eq ItemNotFoundException # | |
Defined in CircularList Methods (==) :: ItemNotFoundException -> ItemNotFoundException -> Bool (/=) :: ItemNotFoundException -> ItemNotFoundException -> Bool | |
Show ItemNotFoundException # | |
Defined in CircularList Methods showsPrec :: Int -> ItemNotFoundException -> ShowS show :: ItemNotFoundException -> String showList :: [ItemNotFoundException] -> ShowS | |
Exception ItemNotFoundException # | |
Defined in CircularList Methods toException :: ItemNotFoundException -> SomeException fromException :: SomeException -> Maybe ItemNotFoundException displayException :: ItemNotFoundException -> String |
data ListIsEmptyException #
Constructors
ListIsEmptyException |
Instances
Eq ListIsEmptyException # | |
Defined in CircularList Methods (==) :: ListIsEmptyException -> ListIsEmptyException -> Bool (/=) :: ListIsEmptyException -> ListIsEmptyException -> Bool | |
Show ListIsEmptyException # | |
Defined in CircularList Methods showsPrec :: Int -> ListIsEmptyException -> ShowS show :: ListIsEmptyException -> String showList :: [ListIsEmptyException] -> ShowS | |
Exception ListIsEmptyException # | |
Defined in CircularList Methods toException :: ListIsEmptyException -> SomeException fromException :: SomeException -> Maybe ListIsEmptyException displayException :: ListIsEmptyException -> String |
data OutOfRangeException #
Constructors
OutOfRangeException |
Instances
Eq OutOfRangeException # | |
Defined in CircularList Methods (==) :: OutOfRangeException -> OutOfRangeException -> Bool (/=) :: OutOfRangeException -> OutOfRangeException -> Bool | |
Show OutOfRangeException # | |
Defined in CircularList Methods showsPrec :: Int -> OutOfRangeException -> ShowS show :: OutOfRangeException -> String showList :: [OutOfRangeException] -> ShowS | |
Exception OutOfRangeException # | |
Defined in CircularList Methods toException :: OutOfRangeException -> SomeException fromException :: SomeException -> Maybe OutOfRangeException displayException :: OutOfRangeException -> String |
data StackIsEmptyException #
Constructors
StackIsEmptyException |
Instances
Eq StackIsEmptyException # | |
Defined in CircularList Methods (==) :: StackIsEmptyException -> StackIsEmptyException -> Bool (/=) :: StackIsEmptyException -> StackIsEmptyException -> Bool | |
Show StackIsEmptyException # | |
Defined in CircularList Methods showsPrec :: Int -> StackIsEmptyException -> ShowS show :: StackIsEmptyException -> String showList :: [StackIsEmptyException] -> ShowS | |
Exception StackIsEmptyException # | |
Defined in CircularList Methods toException :: StackIsEmptyException -> SomeException fromException :: SomeException -> Maybe StackIsEmptyException displayException :: StackIsEmptyException -> String |
data CircularList #
The list.
Constructors
CircularList Current (Vector Item) [Current] |
Instances
Eq CircularList # | |
Defined in CircularList | |
Show CircularList # | |
Defined in CircularList Methods showsPrec :: Int -> CircularList -> ShowS show :: CircularList -> String showList :: [CircularList] -> ShowS |
fromList :: Int -> [Int] -> CircularList #
Make a new CircularList (of size N) from a list.
toList :: CircularList -> [Int] #
Turn the circular list into a list (from current).
size :: CircularList -> Int #
Get the length of the list.
allocated :: CircularList -> Int #
Get the allocated (max) length of the list.
isEmpty :: CircularList -> Bool #
Check, if list is empty.
isIn :: Int -> CircularList -> Bool #
Check, if item is in the list.
get :: CircularList -> Item #
Get the current element.
forward :: CircularList -> CircularList #
Moving current forward.
insert :: Int -> CircularList -> CircularList #
Insert item into list (after current).
Note: The new item cannot be already in the list. Note: Item needs to be in the range (we do not append to the list).
remove :: CircularList -> CircularList #
Remove the item from the list (after the current item).
move :: Int -> CircularList -> CircularList #
Move current to ...
push :: CircularList -> CircularList #
Push the current item on the stack.
pop :: CircularList -> CircularList #
Pop the stack and move to that item.