Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | Haskell2010 |
Algorithms.LogarithmicMethod
Description
Synopsis
- newtype InsertionOnly static a = InsertionOnly [Maybe (static a)]
- empty :: InsertionOnly static a
- class LogarithmicMethodDS static a where
- insert :: LogarithmicMethodDS static a => a -> InsertionOnly static a -> InsertionOnly static a
- queryWith :: Monoid m => (static a -> m) -> InsertionOnly static a -> m
Documentation
newtype InsertionOnly static a Source #
Represents an insertion-only data structure built from static data structures.
In particular, we maintain O(logn) static data structures of sizes 2i, for i∈[0..clogn].
Constructors
InsertionOnly [Maybe (static a)] |
Instances
empty :: InsertionOnly static a Source #
Builds an empty structure
class LogarithmicMethodDS static a where Source #
Minimal complete definition
Methods
singleton :: a -> static a Source #
Create a new static data structure storing only one value.
build :: NonEmpty a -> static a Source #
Given a NonEmpty list of a's build a static a.
merge :: static a -> static a -> static a Source #
Merges two structurs of the same size. Has a default implementation via build in case the static structure is Foldable1.
insert :: LogarithmicMethodDS static a => a -> InsertionOnly static a -> InsertionOnly static a Source #
Inserts an element into the data structure
running time: O(M(n)logn/n), where M(n) is the time required to merge two data structures of size n.
queryWith :: Monoid m => (static a -> m) -> InsertionOnly static a -> m Source #
Given a decomposable query algorithm for the static structure, lift it to a query algorithm on the insertion only structure.
pre: (As indicated by the Monoid constraint), the query answer should be decomposable. I.e. we should be able to anser the query on a set A∪B by answering the query on A and B separately, and combining their results.
running time: O(Q(n)logn), where Q(n) is the query time on the static structure.