Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/pkg/datastructures/doc/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 14.9.2025 mit Größe 83 kB image not shown  

Quelle  datastructures.tex   Sprache: Latech

 
% generated by GAPDoc2LaTeX from XML source (Frank Luebeck)
\documentclass[a4paper,11pt]{report}

\usepackage[top=37mm,bottom=37mm,left=27mm,right=27mm]{geometry}
\sloppy
\pagestyle{myheadings}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\usepackage{makeidx}
\makeindex
\usepackage{color}
\definecolor{FireBrick}{rgb}{0.5812,0.0074,0.0083}
\definecolor{RoyalBlue}{rgb}{0.0236,0.0894,0.6179}
\definecolor{RoyalGreen}{rgb}{0.0236,0.6179,0.0894}
\definecolor{RoyalRed}{rgb}{0.6179,0.0236,0.0894}
\definecolor{LightBlue}{rgb}{0.8544,0.9511,1.0000}
\definecolor{Black}{rgb}{0.0,0.0,0.0}

\definecolor{linkColor}{rgb}{0.0,0.0,0.554}
\definecolor{citeColor}{rgb}{0.0,0.0,0.554}
\definecolor{fileColor}{rgb}{0.0,0.0,0.554}
\definecolor{urlColor}{rgb}{0.0,0.0,0.554}
\definecolor{promptColor}{rgb}{0.0,0.0,0.589}
\definecolor{brkpromptColor}{rgb}{0.589,0.0,0.0}
\definecolor{gapinputColor}{rgb}{0.589,0.0,0.0}
\definecolor{gapoutputColor}{rgb}{0.0,0.0,0.0}

%%  for a long time these were red and blue by default,
%%  now black, but keep variables to overwrite
\definecolor{FuncColor}{rgb}{0.0,0.0,0.0}
%% strange name because of pdflatex bug:
\definecolor{Chapter }{rgb}{0.0,0.0,0.0}
\definecolor{DarkOlive}{rgb}{0.1047,0.2412,0.0064}


\usepackage{fancyvrb}

\usepackage{mathptmx,helvet}
\usepackage[T1]{fontenc}
\usepackage{textcomp}


\usepackage[
            pdftex=true,
            bookmarks=true,        
            a4paper=true,
            pdftitle={Written with GAPDoc},
            pdfcreator={LaTeX with hyperref package / GAPDoc},
            colorlinks=true,
            backref=page,
            breaklinks=true,
            linkcolor=linkColor,
            citecolor=citeColor,
            filecolor=fileColor,
            urlcolor=urlColor,
            pdfpagemode={UseNone}, 
           ]{hyperref}

\newcommand{\maintitlesize}{\fontsize{50}{55}\selectfont}

% write page numbers to a .pnr log file for online help
\newwrite\pagenrlog
\immediate\openout\pagenrlog =\jobname.pnr
\immediate\write\pagenrlog{PAGENRS := [}
\newcommand{\logpage}[1]{\protect\write\pagenrlog{#1, \thepage,}}
%% were never documented, give conflicts with some additional packages

\newcommand{\GAP}{\textsf{GAP}}

%% nicer description environments, allows long labels
\usepackage{enumitem}
\setdescription{style=nextline}

%% depth of toc
\setcounter{tocdepth}{1}





%% command for ColorPrompt style examples
\newcommand{\gapprompt}[1]{\color{promptColor}{\bfseries #1}}
\newcommand{\gapbrkprompt}[1]{\color{brkpromptColor}{\bfseries #1}}
\newcommand{\gapinput}[1]{\color{gapinputColor}{#1}}


\begin{document}

\logpage{[ 0, 0, 0 ]}
\begin{titlepage}
\mbox{}\vfill

\begin{center}{\maintitlesize \textbf{ datastructures \mbox{}}}\\
\vfill

\hypersetup{pdftitle= datastructures }
\markright{\scriptsize \mbox{}\hfill  datastructures  \hfill\mbox{}}
{\Huge \textbf{ Collection of standard data structures for \textsf{GAP} \mbox{}}}\\
\vfill

{\Huge  0.4.0 \mbox{}}\\[1cm]
{ 14 October 2025 \mbox{}}\\[1cm]
\mbox{}\\[2cm]
{\Large \textbf{ Markus Pfeiffer\\
    \mbox{}}}\\
{\Large \textbf{ Max Horn\\
    \mbox{}}}\\
{\Large \textbf{ Christopher Jefferson\\
    \mbox{}}}\\
{\Large \textbf{ Steve Linton\\
    \mbox{}}}\\
\hypersetup{pdfauthor= Markus Pfeiffer\\
    ;  Max Horn\\
    ;  Christopher Jefferson\\
    ;  Steve Linton\\
    }
\end{center}\vfill

\mbox{}\\
{\mbox{}\\
\small \noindent \textbf{ Markus Pfeiffer\\
    }  Email: \href{mailto://markus.pfeiffer@st-andrews.ac.uk} {\texttt{markus.pfeiffer@st\texttt{\symbol{45}}andrews.ac.uk}}\\
  Homepage: \href{http://www.morphism.de/~markusp} {\texttt{http://www.morphism.de/\texttt{\symbol{126}}markusp}}\\
  Address\begin{minipage}[t]{8cm}\noindent
 School of Computer Science\\
 University of St Andrews\\
 Jack Cole Building, North Haugh\\
 St Andrews, Fife, KY16 9SX\\
 United Kingdom\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{ Max Horn\\
    }  Email: \href{mailto://mhorn@rptu.de} {\texttt{mhorn@rptu.de}}\\
  Homepage: \href{https://www.quendi.de/math} {\texttt{https://www.quendi.de/math}}\\
  Address\begin{minipage}[t]{8cm}\noindent
 Fachbereich Mathematik\\
 RPTU Kaiserslautern\texttt{\symbol{45}}Landau\\
 Gottlieb\texttt{\symbol{45}}Daimler\texttt{\symbol{45}}Stra{\ss}e 48\\
 67663 Kaiserslautern\\
 Germany\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{ Christopher Jefferson\\
    }  Email: \href{mailto://caj21@st-andrews.ac.uk} {\texttt{caj21@st\texttt{\symbol{45}}andrews.ac.uk}}\\
  Homepage: \href{http://caj.host.cs.st-andrews.ac.uk/} {\texttt{http://caj.host.cs.st\texttt{\symbol{45}}andrews.ac.uk/}}\\
  Address\begin{minipage}[t]{8cm}\noindent
 School of Computer Science\\
 University of St Andrews\\
 Jack Cole Building, North Haugh\\
 St Andrews, Fife, KY16 9SX\\
 United Kingdom\\
 \end{minipage}
}\\
{\mbox{}\\
\small \noindent \textbf{ Steve Linton\\
    }  Email: \href{mailto://steve.linton@st-andrews.ac.uk} {\texttt{steve.linton@st\texttt{\symbol{45}}andrews.ac.uk}}\\
  Homepage: \href{http://sl4.host.cs.st-andrews.ac.uk/} {\texttt{http://sl4.host.cs.st\texttt{\symbol{45}}andrews.ac.uk/}}\\
  Address\begin{minipage}[t]{8cm}\noindent
 School of Computer Science\\
 University of St Andrews\\
 Jack Cole Building, North Haugh\\
 St Andrews, Fife, KY16 9SX\\
 United Kingdom\\
 \end{minipage}
}\\
\end{titlepage}

\newpage\setcounter{page}{2}
{\small 
\section*{Copyright}
\logpage{[ 0, 0, 1 ]}
 {\copyright} 2015\texttt{\symbol{45}}18 by Chris Jefferson, Steve Linton,
Markus Pfeiffer, Max Horn, Reimer Behrends and others

 \textsf{datastructures} package is free software; you can redistribute it and/or modify it under the
terms of the \href{https://www.fsf.org/licenses/gpl.html} {GNU General Public License} as published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version. \mbox{}}\\[1cm]
{\small 
\section*{Acknowledgements}
\logpage{[ 0, 0, 2 ]}
 We appreciate very much all past and future comments, suggestions and
contributions to this package and its documentation provided by \textsf{GAP} users and developers. \mbox{}}\\[1cm]
\newpage

\def\contentsname{Contents\logpage{[ 0, 0, 3 ]}}

\tableofcontents
\newpage

   
\chapter{\textcolor{Chapter }{Introduction}}\label{Intro}
\logpage{[ 1, 0, 0 ]}
\hyperdef{L}{X7DFB63A97E67C0A1}{}
{
  
\section{\textcolor{Chapter }{Purpose and goals of this package}}\logpage{[ 1, 1, 0 ]}
\hyperdef{L}{X7F0445BA85C0D680}{}
{
  The \textsf{datastructures} package for \textsf{GAP} has two main goals: 
\begin{itemize}
\item Provide abstract interfaces for commonly used datastructures
\item Provide good low\texttt{\symbol{45}}level implementations for these
datastructures
\end{itemize}
 \textsf{datastructures} requires building of a kernel module for \textsf{GAP} to function, please refer to Chapter \ref{install} for details; the package is not automatically loaded by \textsf{GAP} after it has been installed. You must load the package with \texttt{LoadPackage("datastructures");} before its functions become available.

 }

 
\section{\textcolor{Chapter }{Overview over this manual}}\logpage{[ 1, 2, 0 ]}
\hyperdef{L}{X786BACDB82918A65}{}
{
  Chapter \ref{install} describes the installation of this package. The remaining chapters describe
the available datastructures in this package with a definition of the
supported API and details about provided implementations. }

 
\section{\textcolor{Chapter }{Feedback}}\label{feedback}
\logpage{[ 1, 3, 0 ]}
\hyperdef{L}{X80D704CC7EBFDF7A}{}
{
  For bug reports, feature requests and suggestions, please use our \href{https://github.com/gap-packages/datastructures/issues} {issue tracker}. }

 }

  
\chapter{\textcolor{Chapter }{Installation}}\label{install}
\logpage{[ 2, 0, 0 ]}
\hyperdef{L}{X8360C04082558A12}{}
{
  \index{\textsf{datastructures}} \textsf{datastructures} does not work without compiling its kernel module, and is not loaded by \textsf{GAP} by default. To load the package run \texttt{LoadPackage("datastructures");} at the \textsf{GAP} prompt. 
\section{\textcolor{Chapter }{Building the Kernel Module}}\logpage{[ 2, 1, 0 ]}
\hyperdef{L}{X8584FE1F8248F0A4}{}
{
  To build the kernel module, you will need 
\begin{itemize}
\item a C compiler, e.g. GCC or Clang
\item GNU Make
\end{itemize}
 To install a released version of this package, extract the package's archive
file into \textsf{GAP}'s \texttt{pkg} folder.

 To install the current development version of this package, obtain the most
recent code from \textsc{GitHub} 
\begin{verbatim}  
        git clone https://github.com/gap-packages/datastructures
      
\end{verbatim}
 To build the kernel module then run the following commands in the package's
directory. 
\begin{verbatim}  
        ./configure
        make
      
\end{verbatim}
 }

 
\section{\textcolor{Chapter }{Building the Documentation}}\logpage{[ 2, 2, 0 ]}
\hyperdef{L}{X7F7AE6058776DF06}{}
{
  To build the package documentation, run the following command in the package's
directory 
\begin{verbatim}  
        gap makedoc.g
      
\end{verbatim}
 }

 }

     
\chapter{\textcolor{Chapter }{Heaps}}\label{Chapter_Heaps}
\logpage{[ 3, 0, 0 ]}
\hyperdef{L}{X876CE0537BBE92BF}{}
{
  

 
\section{\textcolor{Chapter }{Introduction}}\label{Chapter_Heaps_Section_Introduction}
\logpage{[ 3, 1, 0 ]}
\hyperdef{L}{X7DFB63A97E67C0A1}{}
{
  

 A \emph{heap} is a tree datastructure such that for any child $C$ of a node $N$ it holds that $C \leq N$, according to some ordering relation $\leq$. 

 The fundamental operations for heaps are Construction, \texttt{Push}ing data onto the heap, \texttt{Peek}ing at the topmost item, and \texttt{Pop}ping the topmost item off of the heap. 

 For a good heap implementation these basic operations should not exceed $O(\log n)$ in runtime where $n$ is the number of items on the heap. 

 We currently provide two types of heaps: Binary Heaps \ref{Section_BinaryHeap} and Pairing Heaps \ref{Section_PairingHeap}.

 

 The following code shows how to use a binary heap. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  !gapprompt@gap>| !gapinput@h := BinaryHeap();|
  <binary heap with 0 entries>
  !gapprompt@gap>| !gapinput@Push(h, 5);|
  !gapprompt@gap>| !gapinput@Push(h, -10);|
  !gapprompt@gap>| !gapinput@Peek(h);|
  5
  !gapprompt@gap>| !gapinput@Pop(h);|
  5
  !gapprompt@gap>| !gapinput@Peek(h);|
  -10
\end{Verbatim}
 

 The following code shows how to use a pairing heap. 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  !gapprompt@gap>| !gapinput@h := PairingHeap( {x,y} -> x.rank > y.rank );|
  <pairing heap with 0 entries>
  !gapprompt@gap>| !gapinput@Push(h, rec( rank  := 5 ));|
  !gapprompt@gap>| !gapinput@Push(h, rec( rank  := 7 ));|
  !gapprompt@gap>| !gapinput@Push(h, rec( rank  := -15 ));|
  !gapprompt@gap>| !gapinput@h;|
  <pairing heap with 3 entries>
  !gapprompt@gap>| !gapinput@Peek(h);|
  rec( rank := -15 )
  !gapprompt@gap>| !gapinput@Pop(h);|
  rec( rank := -15 )
\end{Verbatim}
 }

 
\section{\textcolor{Chapter }{API}}\label{Chapter_Heaps_Section_API}
\logpage{[ 3, 2, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 For the purposes of the \textsf{datastructures}, we provide a category \texttt{IsHeap} (\ref{IsHeap:for IsObject}) . Every implementation of a heap in the category \texttt{IsHeap} (\ref{IsHeap:for IsObject}) must follow the API described in this section. 

 

\subsection{\textcolor{Chapter }{IsHeap (for IsObject)}}
\logpage{[ 3, 2, 1 ]}\nobreak
\hyperdef{L}{X85D1DDCF86FD53EB}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsHeap({\mdseries\slshape arg})\index{IsHeap@\texttt{IsHeap}!for IsObject}
\label{IsHeap:for IsObject}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 The category of heaps. Every object in this category promises to support the
API described in this section. }

 

\subsection{\textcolor{Chapter }{Heap}}
\logpage{[ 3, 2, 2 ]}\nobreak
\hyperdef{L}{X81244A537F7E02FC}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Heap({\mdseries\slshape arg})\index{Heap@\texttt{Heap}}
\label{Heap}
}\hfill{\scriptsize (function)}}\\


 Wrapper function around constructors }

 

\subsection{\textcolor{Chapter }{NewHeap (for IsHeap, IsObject, IsObject)}}
\logpage{[ 3, 2, 3 ]}\nobreak
\hyperdef{L}{X84E3B88F7FD83B3C}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NewHeap({\mdseries\slshape [filter, func, data]})\index{NewHeap@\texttt{NewHeap}!for IsHeap, IsObject, IsObject}
\label{NewHeap:for IsHeap, IsObject, IsObject}
}\hfill{\scriptsize (constructor)}}\\
\textbf{\indent Returns:}
a heap 



 Construct a new heap 

 }

 

\subsection{\textcolor{Chapter }{Push (for IsHeap, IsObject)}}
\logpage{[ 3, 2, 4 ]}\nobreak
\hyperdef{L}{X812240D187506B40}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Push({\mdseries\slshape heap, object})\index{Push@\texttt{Push}!for IsHeap, IsObject}
\label{Push:for IsHeap, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Puts the object \mbox{\texttt{\mdseries\slshape object}} a new object onto \mbox{\texttt{\mdseries\slshape heap}}. 

 }

 

\subsection{\textcolor{Chapter }{Peek (for IsHeap)}}
\logpage{[ 3, 2, 5 ]}\nobreak
\hyperdef{L}{X78052DBE7B563C2C}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Peek({\mdseries\slshape heap})\index{Peek@\texttt{Peek}!for IsHeap}
\label{Peek:for IsHeap}
}\hfill{\scriptsize (operation)}}\\


 Inspect the item at the top of \mbox{\texttt{\mdseries\slshape heap}}. 

 }

 

\subsection{\textcolor{Chapter }{Pop (for IsHeap)}}
\logpage{[ 3, 2, 6 ]}\nobreak
\hyperdef{L}{X783D92BE8344CBD3}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Pop({\mdseries\slshape heap})\index{Pop@\texttt{Pop}!for IsHeap}
\label{Pop:for IsHeap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an object 



 Remove the top item from \mbox{\texttt{\mdseries\slshape heap}} and return it. }

 

\subsection{\textcolor{Chapter }{Merge (for IsHeap, IsHeap)}}
\logpage{[ 3, 2, 7 ]}\nobreak
\hyperdef{L}{X84E27F257EA4556A}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Merge({\mdseries\slshape heap1, heap2})\index{Merge@\texttt{Merge}!for IsHeap, IsHeap}
\label{Merge:for IsHeap, IsHeap}
}\hfill{\scriptsize (operation)}}\\


 Merge two heaps (of the same type) }

 Heaps also support \texttt{IsEmpty} (\textbf{Reference: IsEmpty}) and \texttt{Size} (\textbf{Reference: Size}) }

 
\section{\textcolor{Chapter }{Binary Heaps}}\label{Section_BinaryHeap}
\logpage{[ 3, 3, 0 ]}
\hyperdef{L}{X7A01096286198C96}{}
{
  

 A binary heap employs a binary tree as its underlying tree datastructure. The
implemenataion of binary heaps in \textsf{datastructures} stores this tree in a flat array which makes it a very good and fast default
choice for general purpose use. In particular, even though other heap
implementations have better theoretical runtime bounds,
well\texttt{\symbol{45}}tuned binary heaps outperform them in many
applications. 

 For some reference see \href{http://stackoverflow.com/questions/6531543} {\texttt{http://stackoverflow.com/questions/6531543}} 

\subsection{\textcolor{Chapter }{BinaryHeap}}
\logpage{[ 3, 3, 1 ]}\nobreak
\hyperdef{L}{X7F627E817F17CD8A}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BinaryHeap({\mdseries\slshape [isLess[, data]]})\index{BinaryHeap@\texttt{BinaryHeap}}
\label{BinaryHeap}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
A binary heap 



 Constructor for binary heaps. The optional argument \mbox{\texttt{\mdseries\slshape isLess}} must be a binary function that performs comparison between two elements on the
heap, and returns \texttt{true} if the first argument is less than the second, and \texttt{false} otherwise. Using the optional argument \mbox{\texttt{\mdseries\slshape data}} the user can give a collection of initial values that are pushed on the stack
after construction. }

 }

 
\section{\textcolor{Chapter }{Pairing Heaps}}\label{Section_PairingHeap}
\logpage{[ 3, 4, 0 ]}
\hyperdef{L}{X82EFFA948516AD5C}{}
{
  

 A pairing heap is a heap datastructure with a very simple implementation in
terms of \textsf{GAP} lists. \texttt{Push} and \texttt{Peek} have $O(1)$ complexity, and \texttt{Pop} has an amortized amortised O(log n), where $n$ is the number of items on the heap. 

 For a reference see \cite{Fredman1986}. 

 

\subsection{\textcolor{Chapter }{PairingHeap}}
\logpage{[ 3, 4, 1 ]}\nobreak
\hyperdef{L}{X7F8B54F282A4B1A7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PairingHeap({\mdseries\slshape [isLess[, data]]})\index{PairingHeap@\texttt{PairingHeap}}
\label{PairingHeap}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
A pairing heap 



 Constructor for pairing heaps. The optional argument \mbox{\texttt{\mdseries\slshape isLess}} must be a binary function that performs comparison between two elements on the
heap, and returns \texttt{true} if the first argument is less than the second, and \texttt{false} otherwise. Using the optional argument \mbox{\texttt{\mdseries\slshape data}} the user can give a collection of initial values that are pushed on the stack
after construction. }

 }

 

 
\section{\textcolor{Chapter }{Declarations}}\label{Chapter_Heaps_Section_Declarations}
\logpage{[ 3, 5, 0 ]}
\hyperdef{L}{X844A8A1F85E6E038}{}
{
  

\subsection{\textcolor{Chapter }{IsBinaryHeapFlatRep (for IsHeap and IsPositionalObjectRep)}}
\logpage{[ 3, 5, 1 ]}\nobreak
\hyperdef{L}{X7BDAA17C7A89C7C7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsBinaryHeapFlatRep({\mdseries\slshape arg})\index{IsBinaryHeapFlatRep@\texttt{IsBinaryHeapFlatRep}!for IsHeap and IsPositionalObjectRep}
\label{IsBinaryHeapFlatRep:for IsHeap and IsPositionalObjectRep}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 

 }

 }

 

 
\section{\textcolor{Chapter }{Implementation}}\label{Chapter_Heaps_Section_Implementation}
\logpage{[ 3, 6, 0 ]}
\hyperdef{L}{X78289A737AF28B39}{}
{
  

\subsection{\textcolor{Chapter }{IsPairingHeapFlatRep (for IsHeap and IsPositionalObjectRep)}}
\logpage{[ 3, 6, 1 ]}\nobreak
\hyperdef{L}{X7D2529247BC9A1A5}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsPairingHeapFlatRep({\mdseries\slshape arg})\index{IsPairingHeapFlatRep@\texttt{IsPairingHeapFlatRep}!for IsHeap and IsPositionalObjectRep}
\label{IsPairingHeapFlatRep:for IsHeap and IsPositionalObjectRep}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 

 }

 }

 }

   
\chapter{\textcolor{Chapter }{Queues and Deques}}\label{Chapter_Queues_and_Deques}
\logpage{[ 4, 0, 0 ]}
\hyperdef{L}{X7E4B7210874702B2}{}
{
  

 
\section{\textcolor{Chapter }{API}}\label{Chapter_Queues_and_Deques_Section_API}
\logpage{[ 4, 1, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 

\subsection{\textcolor{Chapter }{IsQueue (for IsObject)}}
\logpage{[ 4, 1, 1 ]}\nobreak
\hyperdef{L}{X82229C878341CDDC}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsQueue({\mdseries\slshape arg})\index{IsQueue@\texttt{IsQueue}!for IsObject}
\label{IsQueue:for IsObject}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 The category of queues. }

 

\subsection{\textcolor{Chapter }{IsDeque (for IsObject)}}
\logpage{[ 4, 1, 2 ]}\nobreak
\hyperdef{L}{X7CD371EE7EB88DA8}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsDeque({\mdseries\slshape arg})\index{IsDeque@\texttt{IsDeque}!for IsObject}
\label{IsDeque:for IsObject}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 The category of deques. }

 

\subsection{\textcolor{Chapter }{PushBack (for IsDeque, IsObject)}}
\logpage{[ 4, 1, 3 ]}\nobreak
\hyperdef{L}{X8372434383E08554}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PushBack({\mdseries\slshape deque, object})\index{PushBack@\texttt{PushBack}!for IsDeque, IsObject}
\label{PushBack:for IsDeque, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Add \mbox{\texttt{\mdseries\slshape object}} to the back of \mbox{\texttt{\mdseries\slshape deque}}. }

 

\subsection{\textcolor{Chapter }{PushFront (for IsDeque, IsObject)}}
\logpage{[ 4, 1, 4 ]}\nobreak
\hyperdef{L}{X7A19020A835C39A7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PushFront({\mdseries\slshape deque, object})\index{PushFront@\texttt{PushFront}!for IsDeque, IsObject}
\label{PushFront:for IsDeque, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Add \mbox{\texttt{\mdseries\slshape object}} to the front of \mbox{\texttt{\mdseries\slshape deque}}. }

 

\subsection{\textcolor{Chapter }{PopBack (for IsDeque)}}
\logpage{[ 4, 1, 5 ]}\nobreak
\hyperdef{L}{X7FFC2AAF85355F50}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PopBack({\mdseries\slshape deque})\index{PopBack@\texttt{PopBack}!for IsDeque}
\label{PopBack:for IsDeque}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
object 



 Remove an element from the back of \mbox{\texttt{\mdseries\slshape deque}} and return it. }

 

\subsection{\textcolor{Chapter }{PopFront (for IsDeque)}}
\logpage{[ 4, 1, 6 ]}\nobreak
\hyperdef{L}{X7CD527F87861A5FE}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PopFront({\mdseries\slshape deque})\index{PopFront@\texttt{PopFront}!for IsDeque}
\label{PopFront:for IsDeque}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
object 



 Remove an element from the front of \mbox{\texttt{\mdseries\slshape deque}} and return it. }

 For queues, this is just an alias for PushBack 

\subsection{\textcolor{Chapter }{Enqueue (for IsQueue, IsObject)}}
\logpage{[ 4, 1, 7 ]}\nobreak
\hyperdef{L}{X80D3DF0B7DF6B8BC}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Enqueue({\mdseries\slshape queue, object})\index{Enqueue@\texttt{Enqueue}!for IsQueue, IsObject}
\label{Enqueue:for IsQueue, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Add \mbox{\texttt{\mdseries\slshape object}} to \mbox{\texttt{\mdseries\slshape queue}}. }

 

\subsection{\textcolor{Chapter }{Dequeue (for IsQueue, IsObject)}}
\logpage{[ 4, 1, 8 ]}\nobreak
\hyperdef{L}{X87D9EF6E84B98629}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Dequeue({\mdseries\slshape queue})\index{Dequeue@\texttt{Dequeue}!for IsQueue, IsObject}
\label{Dequeue:for IsQueue, IsObject}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
object 



 Remove an object from the front of \mbox{\texttt{\mdseries\slshape queue}} and return it. }

 

\subsection{\textcolor{Chapter }{Capacity (for IsQueue)}}
\logpage{[ 4, 1, 9 ]}\nobreak
\hyperdef{L}{X84CF84A087CA6719}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Capacity({\mdseries\slshape arg})\index{Capacity@\texttt{Capacity}!for IsQueue}
\label{Capacity:for IsQueue}
}\hfill{\scriptsize (attribute)}}\\


 Allocated storage capacity of \mbox{\texttt{\mdseries\slshape queue}}. }

 

\subsection{\textcolor{Chapter }{Capacity (for IsDeque)}}
\logpage{[ 4, 1, 10 ]}\nobreak
\hyperdef{L}{X7AFCE0EC7D282807}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Capacity({\mdseries\slshape arg})\index{Capacity@\texttt{Capacity}!for IsDeque}
\label{Capacity:for IsDeque}
}\hfill{\scriptsize (attribute)}}\\


 Allocated storage capacity of \mbox{\texttt{\mdseries\slshape deque}}. }

 

\subsection{\textcolor{Chapter }{Length (for IsQueue)}}
\logpage{[ 4, 1, 11 ]}\nobreak
\hyperdef{L}{X86CB9F747A49AA9F}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Length({\mdseries\slshape arg})\index{Length@\texttt{Length}!for IsQueue}
\label{Length:for IsQueue}
}\hfill{\scriptsize (attribute)}}\\


 Number of elements in \mbox{\texttt{\mdseries\slshape queue}}. }

 

\subsection{\textcolor{Chapter }{Length (for IsDeque)}}
\logpage{[ 4, 1, 12 ]}\nobreak
\hyperdef{L}{X78F8FB38830FF16A}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Length({\mdseries\slshape arg})\index{Length@\texttt{Length}!for IsDeque}
\label{Length:for IsDeque}
}\hfill{\scriptsize (attribute)}}\\


 Number of elements in \mbox{\texttt{\mdseries\slshape deque}}. }

 }

 
\section{\textcolor{Chapter }{Deques implemented using plain lists}}\label{Chapter_Queues_and_Deques_Section_Deques_implemented_using_plain_lists}
\logpage{[ 4, 2, 0 ]}
\hyperdef{L}{X7E65C2D087E8B8CA}{}
{
  

 \textsf{datastructures} implements deques using a circular buffer stored in a \textsf{GAP} a plain list, wrapped in a positional object ( (\textbf{Reference: Positional Objects})). 

 The five positions in such a deque \texttt{Q} have the following purpose 

 
\begin{itemize}
\item \texttt{Q![1]} \texttt{\symbol{45}} head, the index in \texttt{Q![5]} of the first element in the deque
\item \texttt{Q![2]} \texttt{\symbol{45}} tail, the index in \texttt{Q![5]} of the last element in the deque
\item \texttt{Q![3]} \texttt{\symbol{45}} capacity, the allocated capacity in the deque
\item \texttt{Q![4]} \texttt{\symbol{45}} factor by which storage is increased if capacity is
exceeded
\item \texttt{Q![5]} \texttt{\symbol{45}} GAP plain list with storage for capacity many entries
\end{itemize}
 

 Global constants \texttt{QHEAD}, \texttt{QTAIL}, \texttt{QCAPACITY}, \texttt{QFACTOR}, and \texttt{QDATA} are bound to reflect the above. 

 When a push fills the deque, its capacity is resized by a factor of \texttt{QFACTOR} using PlistDequeExpand. A new empty plist is allocated and all current entries
of the deque are copied into the new plist with the head entry at index 1. 

 The deque is empty if and only if head = tail and the entry that head and tail
point to in the storage list is unbound. 

\subsection{\textcolor{Chapter }{PlistDeque}}
\logpage{[ 4, 2, 1 ]}\nobreak
\hyperdef{L}{X7817028981968371}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDeque({\mdseries\slshape [capacity[, factor]]})\index{PlistDeque@\texttt{PlistDeque}}
\label{PlistDeque}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
a deque 



 Constructor for plist based deques. The optional argument \mbox{\texttt{\mdseries\slshape capacity}} must be a positive integer and is the capacity of the created deque, and the
optional argument \mbox{\texttt{\mdseries\slshape factor}} must be a rational number greater than one which is the factor by which the
storage of the deque is increased if it runs out of capacity when an object is
put on the queue. }

 

\subsection{\textcolor{Chapter }{PlistDequePushFront}}
\logpage{[ 4, 2, 2 ]}\nobreak
\hyperdef{L}{X7BF75DB47D46C91E}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePushFront({\mdseries\slshape deque, object})\index{PlistDequePushFront@\texttt{PlistDequePushFront}}
\label{PlistDequePushFront}
}\hfill{\scriptsize (function)}}\\


 Push \mbox{\texttt{\mdseries\slshape object}} to the front of \mbox{\texttt{\mdseries\slshape deque}}. }

 

\subsection{\textcolor{Chapter }{PlistDequePushBack}}
\logpage{[ 4, 2, 3 ]}\nobreak
\hyperdef{L}{X7E8676DB84B2C360}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePushBack({\mdseries\slshape deque, object})\index{PlistDequePushBack@\texttt{PlistDequePushBack}}
\label{PlistDequePushBack}
}\hfill{\scriptsize (function)}}\\


 Push \mbox{\texttt{\mdseries\slshape object}} to the back of \mbox{\texttt{\mdseries\slshape deque}}. }

 

\subsection{\textcolor{Chapter }{PlistDequePopFront}}
\logpage{[ 4, 2, 4 ]}\nobreak
\hyperdef{L}{X8704C6BD875D0385}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePopFront({\mdseries\slshape deque})\index{PlistDequePopFront@\texttt{PlistDequePopFront}}
\label{PlistDequePopFront}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
object or fail 



 Pop object from the front of \mbox{\texttt{\mdseries\slshape deque}} and return it. If \mbox{\texttt{\mdseries\slshape deque}} is empty, returns \texttt{fail}. }

 

\subsection{\textcolor{Chapter }{PlistDequePopBack}}
\logpage{[ 4, 2, 5 ]}\nobreak
\hyperdef{L}{X86B4266878A93741}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePopBack({\mdseries\slshape deque})\index{PlistDequePopBack@\texttt{PlistDequePopBack}}
\label{PlistDequePopBack}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
object or fail 



 Pop object from the back of \mbox{\texttt{\mdseries\slshape deque}} and return it. If \mbox{\texttt{\mdseries\slshape deque}} is empty, returns \texttt{fail}. }

 

\subsection{\textcolor{Chapter }{PlistDequePeekFront}}
\logpage{[ 4, 2, 6 ]}\nobreak
\hyperdef{L}{X841543137B0F720C}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePeekFront({\mdseries\slshape deque})\index{PlistDequePeekFront@\texttt{PlistDequePeekFront}}
\label{PlistDequePeekFront}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
object or fail 



 Returns the object at the front \mbox{\texttt{\mdseries\slshape deque}} without removing it. If \mbox{\texttt{\mdseries\slshape deque}} is empty, returns \texttt{fail}. }

 

\subsection{\textcolor{Chapter }{PlistDequePeekBack}}
\logpage{[ 4, 2, 7 ]}\nobreak
\hyperdef{L}{X81D966A282FB7872}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequePeekBack({\mdseries\slshape deque})\index{PlistDequePeekBack@\texttt{PlistDequePeekBack}}
\label{PlistDequePeekBack}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
object or fail 



 Returns the object at the back \mbox{\texttt{\mdseries\slshape deque}} without removing it. If \mbox{\texttt{\mdseries\slshape deque}} is empty, returns \texttt{fail}. }

 

\subsection{\textcolor{Chapter }{PlistDequeExpand}}
\logpage{[ 4, 2, 8 ]}\nobreak
\hyperdef{L}{X7B35697B780919D7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlistDequeExpand({\mdseries\slshape deque})\index{PlistDequeExpand@\texttt{PlistDequeExpand}}
\label{PlistDequeExpand}
}\hfill{\scriptsize (function)}}\\


 Helper function to expand the capacity of \mbox{\texttt{\mdseries\slshape deque}} by the configured factor. }

 }

 

 \emph{Queues} are linear data structure that allow adding elements at the end of the queue,
and removing elements from the front. A \emph{deque} is a \emph{double\texttt{\symbol{45}}ended queue}; a linear data structure that allows access to objects at both ends.

 

 The API that objects that lie in \texttt{IsQueue} (\ref{IsQueue:for IsObject}) and \texttt{IsDeque} (\ref{IsDeque:for IsObject}) must implement the API set out below. 

 \textsf{datastructures} provides 

 }

   
\chapter{\textcolor{Chapter }{Union\texttt{\symbol{45}}Find}}\label{Chapter_Union-Find}
\logpage{[ 5, 0, 0 ]}
\hyperdef{L}{X7C0CE80081C1D1A2}{}
{
  

 
\section{\textcolor{Chapter }{Introduction}}\label{Chapter_Union-Find_Section_Introduction}
\logpage{[ 5, 1, 0 ]}
\hyperdef{L}{X7DFB63A97E67C0A1}{}
{
  

 \textsf{datastructures} defines the interface for mutable data structures representing partitions of \texttt{[1..n]}, commonly known as union\texttt{\symbol{45}}find data structures. Key
operations are \texttt{Unite} (\ref{Unite:for IsPartitionDS and IsMutable, IsPosInt, IsPosInt}) which fuses two parts of a partition and \texttt{Representative} (\ref{Representative:for IsPartitionDS, IsPosInt}) which returns a canonical representative of the part containing a given point. 

 }

 
\section{\textcolor{Chapter }{API}}\label{Chapter_Union-Find_Section_API}
\logpage{[ 5, 2, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 

\subsection{\textcolor{Chapter }{IsPartitionDS (for IsObject)}}
\logpage{[ 5, 2, 1 ]}\nobreak
\hyperdef{L}{X804726FA84A7EA0F}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsPartitionDS({\mdseries\slshape arg})\index{IsPartitionDS@\texttt{IsPartitionDS}!for IsObject}
\label{IsPartitionDS:for IsObject}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 Category of datastructures representing partitions. Equality is identity and
family is ignored. }

 

\subsection{\textcolor{Chapter }{PartitionDSCons (for IsPartitionDS, IsPosInt)}}
\logpage{[ 5, 2, 2 ]}\nobreak
\hyperdef{L}{X794FFC5983C63468}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDSCons({\mdseries\slshape filter, n})\index{PartitionDSCons@\texttt{PartitionDSCons}!for IsPartitionDS, IsPosInt}
\label{PartitionDSCons:for IsPartitionDS, IsPosInt}
}\hfill{\scriptsize (constructor)}}\\


 Family containing all partition data structures Returns the trivial partition
of the set \texttt{[1..n]}. }

 

\subsection{\textcolor{Chapter }{PartitionDSCons (for IsPartitionDS, IsCyclotomicCollColl)}}
\logpage{[ 5, 2, 3 ]}\nobreak
\hyperdef{L}{X7EAC43E97BE451C0}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDSCons({\mdseries\slshape filter, partition})\index{PartitionDSCons@\texttt{PartitionDSCons}!for IsPartitionDS, IsCyclotomicCollColl}
\label{PartitionDSCons:for IsPartitionDS, IsCyclotomicCollColl}
}\hfill{\scriptsize (constructor)}}\\


 Returns the union find structure of \mbox{\texttt{\mdseries\slshape partition}}. }

 

\subsection{\textcolor{Chapter }{PartitionDS (for IsFunction, IsPosInt)}}
\logpage{[ 5, 2, 4 ]}\nobreak
\hyperdef{L}{X85E4403778DC83A0}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDS({\mdseries\slshape filter, n})\index{PartitionDS@\texttt{PartitionDS}!for IsFunction, IsPosInt}
\label{PartitionDS:for IsFunction, IsPosInt}
}\hfill{\scriptsize (operation)}}\\


 Returns the trivial partition of the set \texttt{[1..n]}. }

 

\subsection{\textcolor{Chapter }{PartitionDS (for IsPosInt)}}
\logpage{[ 5, 2, 5 ]}\nobreak
\hyperdef{L}{X876385547BD14FDD}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDS({\mdseries\slshape n})\index{PartitionDS@\texttt{PartitionDS}!for IsPosInt}
\label{PartitionDS:for IsPosInt}
}\hfill{\scriptsize (operation)}}\\


 Returns the trivial partition of the set \texttt{[1..n]}. }

 

\subsection{\textcolor{Chapter }{PartitionDS (for IsFunction, IsCyclotomicCollColl)}}
\logpage{[ 5, 2, 6 ]}\nobreak
\hyperdef{L}{X7B0B222583188A6B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDS({\mdseries\slshape filter, partition})\index{PartitionDS@\texttt{PartitionDS}!for IsFunction, IsCyclotomicCollColl}
\label{PartitionDS:for IsFunction, IsCyclotomicCollColl}
}\hfill{\scriptsize (operation)}}\\


 Returns the union find structure of \mbox{\texttt{\mdseries\slshape partition}}. }

 

\subsection{\textcolor{Chapter }{PartitionDS (for IsCyclotomicCollColl)}}
\logpage{[ 5, 2, 7 ]}\nobreak
\hyperdef{L}{X8796F318875443C4}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartitionDS({\mdseries\slshape partition})\index{PartitionDS@\texttt{PartitionDS}!for IsCyclotomicCollColl}
\label{PartitionDS:for IsCyclotomicCollColl}
}\hfill{\scriptsize (operation)}}\\


 Returns the union find structure of \mbox{\texttt{\mdseries\slshape partition}}. }

 

\subsection{\textcolor{Chapter }{Representative (for IsPartitionDS, IsPosInt)}}
\logpage{[ 5, 2, 8 ]}\nobreak
\hyperdef{L}{X8344F7007AD2C44B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Representative({\mdseries\slshape unionfind, k})\index{Representative@\texttt{Representative}!for IsPartitionDS, IsPosInt}
\label{Representative:for IsPartitionDS, IsPosInt}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
a positive integer 



 Returns a canonical representative of the part of the partition that \mbox{\texttt{\mdseries\slshape k}} is contained in. }

 

\subsection{\textcolor{Chapter }{Unite (for IsPartitionDS and IsMutable, IsPosInt, IsPosInt)}}
\logpage{[ 5, 2, 9 ]}\nobreak
\hyperdef{L}{X7FABCE367DC2F82B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Unite({\mdseries\slshape unionfind, k1, k2})\index{Unite@\texttt{Unite}!for IsPartitionDS and IsMutable, IsPosInt, IsPosInt}
\label{Unite:for IsPartitionDS and IsMutable, IsPosInt, IsPosInt}
}\hfill{\scriptsize (operation)}}\\


 Fuses the parts of the partition \mbox{\texttt{\mdseries\slshape unionfind}} containing \mbox{\texttt{\mdseries\slshape k1}} and \mbox{\texttt{\mdseries\slshape k2}}. }

 

\subsection{\textcolor{Chapter }{RootsIteratorOfPartitionDS (for IsPartitionDS)}}
\logpage{[ 5, 2, 10 ]}\nobreak
\hyperdef{L}{X7A41C16979664337}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{RootsIteratorOfPartitionDS({\mdseries\slshape unionfind})\index{RootsIteratorOfPartitionDS@\texttt{RootsIteratorOfPartitionDS}!for IsPartitionDS}
\label{RootsIteratorOfPartitionDS:for IsPartitionDS}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an iterator 



 Returns an iterator that runs through canonical representatives of parts of
the partition \mbox{\texttt{\mdseries\slshape unionfind}}. }

 

\subsection{\textcolor{Chapter }{RootsOfPartitionDS (for IsPartitionDS)}}
\logpage{[ 5, 2, 11 ]}\nobreak
\hyperdef{L}{X7EA363F57FC53B4E}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{RootsOfPartitionDS({\mdseries\slshape unionfind})\index{RootsOfPartitionDS@\texttt{RootsOfPartitionDS}!for IsPartitionDS}
\label{RootsOfPartitionDS:for IsPartitionDS}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
A list. 



 Returns a list of the canonical representatives of the parts of the partition \mbox{\texttt{\mdseries\slshape unionfind}}. }

 

\subsection{\textcolor{Chapter }{NumberParts (for IsPartitionDS)}}
\logpage{[ 5, 2, 12 ]}\nobreak
\hyperdef{L}{X83E6F1DE84ABFB69}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NumberParts({\mdseries\slshape unionfind})\index{NumberParts@\texttt{NumberParts}!for IsPartitionDS}
\label{NumberParts:for IsPartitionDS}
}\hfill{\scriptsize (attribute)}}\\
\textbf{\indent Returns:}
a positive integer 



 Returns the number of parts of the partition \mbox{\texttt{\mdseries\slshape unionfind}}. }

 

\subsection{\textcolor{Chapter }{SizeUnderlyingSetDS (for IsPartitionDS)}}
\logpage{[ 5, 2, 13 ]}\nobreak
\hyperdef{L}{X8635245A83D7DC1B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{SizeUnderlyingSetDS({\mdseries\slshape unionfind})\index{SizeUnderlyingSetDS@\texttt{SizeUnderlyingSetDS}!for IsPartitionDS}
\label{SizeUnderlyingSetDS:for IsPartitionDS}
}\hfill{\scriptsize (attribute)}}\\
\textbf{\indent Returns:}
a positive integer 



 Returns the size of the underlying set of the partition \mbox{\texttt{\mdseries\slshape unionfind}}. }

 

\subsection{\textcolor{Chapter }{PartsOfPartitionDS (for IsPartitionDS)}}
\logpage{[ 5, 2, 14 ]}\nobreak
\hyperdef{L}{X8716AC8F79820C86}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PartsOfPartitionDS({\mdseries\slshape unionfind})\index{PartsOfPartitionDS@\texttt{PartsOfPartitionDS}!for IsPartitionDS}
\label{PartsOfPartitionDS:for IsPartitionDS}
}\hfill{\scriptsize (attribute)}}\\
\textbf{\indent Returns:}
a list of lists 



 Returns the partition \mbox{\texttt{\mdseries\slshape unionfind}} as a list of lists. }

 }

 

 }

   
\chapter{\textcolor{Chapter }{Hash Functions}}\label{Chapter_HashFunctions}
\logpage{[ 6, 0, 0 ]}
\hyperdef{L}{X7AE36B967EB1382B}{}
{
  

 
\section{\textcolor{Chapter }{Introduction}}\label{Chapter_Hash_Functions_Section_Introduction}
\logpage{[ 6, 1, 0 ]}
\hyperdef{L}{X7DFB63A97E67C0A1}{}
{
  

 A hash function in \textsf{datastructures} is a function $H$ which maps a value $X$ to a small integer (where a small integer is an integer in the range \texttt{[\texttt{\symbol{45}}2\texttt{\symbol{94}}28..2\texttt{\symbol{94}}28\texttt{\symbol{45}}1]} on a 32\texttt{\symbol{45}}bit system, and \texttt{[\texttt{\symbol{45}}2\texttt{\symbol{94}}60..2\texttt{\symbol{94}}60\texttt{\symbol{45}}1]} on a 64\texttt{\symbol{45}}bit system), under the requirement that if $X=Y$, then $H(X)=H(Y)$. 

 A variety of hash functions is provided by \textsf{datastructures}, with different behaviours. A bad choice of hash function can lead to serious
performance problems. 

 \textsf{datastructures} does not guarantee consistency of hash values across release or \textsf{GAP} sessions. }

 
\section{\textcolor{Chapter }{Hash Functions for Basic Types}}\label{Chapter_Hash_Functions_Section_Hash_Functions_for_Basic_Types}
\logpage{[ 6, 2, 0 ]}
\hyperdef{L}{X7A441DD97E6C78A6}{}
{
  

\subsection{\textcolor{Chapter }{HashBasic}}
\logpage{[ 6, 2, 1 ]}\nobreak
\hyperdef{L}{X85E86FF080A3A37A}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{HashBasic({\mdseries\slshape obj...})\index{HashBasic@\texttt{HashBasic}}
\label{HashBasic}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
a small integer 



 Hashes any values built inductively from 
\begin{itemize}
\item  built\texttt{\symbol{45}}in types, namely integers, booleans, permutations,
transformations, partial permutations, and
\item  constructors for lists and records. 
\end{itemize}
 

 This function is variadic, treating more than one argument as equivalent to a
list containing the arguments, that is \texttt{HashBasic(x,y,z) = HashBasic([x,y,z])}. }

 }

 
\section{\textcolor{Chapter }{Hash Functions for Permutation Groups}}\label{Chapter_Hash_Functions_Section_Hash_Functions_for_Permutation_Groups}
\logpage{[ 6, 3, 0 ]}
\hyperdef{L}{X78424208807F992D}{}
{
  

 \textsf{datastructures} provides two hash functions for permutation groups; \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Fast} (\ref{HashuScorePermGroupuScoreFast}) is the faster one, with higher likelihood of collisions and \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Complete} (\ref{HashuScorePermGroupuScoreComplete}) is slower but provides a lower likelihood of collisions. 

\subsection{\textcolor{Chapter }{Hash{\textunderscore}PermGroup{\textunderscore}Fast}}
\logpage{[ 6, 3, 1 ]}\nobreak
\hyperdef{L}{X848AD86F8089106F}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Hash{\textunderscore}PermGroup{\textunderscore}Fast({\mdseries\slshape group})\index{Hash{\textunderscore}PermGroup{\textunderscore}Fast@\texttt{Hash{\textunderscore}}\-\texttt{Perm}\-\texttt{Group{\textunderscore}}\-\texttt{Fast}}
\label{HashuScorePermGroupuScoreFast}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
a small integer 



 \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Fast} (\ref{HashuScorePermGroupuScoreFast}) is faster than \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Complete} (\ref{HashuScorePermGroupuScoreComplete}), but will return the same value for groups with the same size, orbits and
degree of transitivity. }

 

\subsection{\textcolor{Chapter }{Hash{\textunderscore}PermGroup{\textunderscore}Complete}}
\logpage{[ 6, 3, 2 ]}\nobreak
\hyperdef{L}{X86FFE7A07E784C24}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Hash{\textunderscore}PermGroup{\textunderscore}Complete({\mdseries\slshape group})\index{Hash{\textunderscore}PermGroup{\textunderscore}Complete@\texttt{Hash{\textunderscore}}\-\texttt{Perm}\-\texttt{Group{\textunderscore}}\-\texttt{Complete}}
\label{HashuScorePermGroupuScoreComplete}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
a small integer 



 \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Complete} (\ref{HashuScorePermGroupuScoreComplete}) is slower than \texttt{Hash{\textunderscore}PermGroup{\textunderscore}Fast} (\ref{HashuScorePermGroupuScoreFast}), but is extremely unlikely to return the same hash for two different groups. }

 }

 }

   
\chapter{\textcolor{Chapter }{Hashmaps}}\label{Chapter_Hashmaps}
\logpage{[ 7, 0, 0 ]}
\hyperdef{L}{X7D62ABFF8416C44C}{}
{
  

 A hash map stores key\texttt{\symbol{45}}value pairs and allows efficient
lookup of keys by using a hash function.

 

 \textsf{datastructures} currently provides a reference implementation of hashmaps using a hashtable
stored in a plain \textsf{GAP} list. 

 
\section{\textcolor{Chapter }{API}}\label{Chapter_Hashmaps_Section_API}
\logpage{[ 7, 1, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 

\subsection{\textcolor{Chapter }{IsHashMap (for IsObject and IsFinite)}}
\logpage{[ 7, 1, 1 ]}\nobreak
\hyperdef{L}{X7C142C0B7AD53629}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsHashMap({\mdseries\slshape arg})\index{IsHashMap@\texttt{IsHashMap}!for IsObject and IsFinite}
\label{IsHashMap:for IsObject and IsFinite}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 Category of hash maps }

 

\subsection{\textcolor{Chapter }{HashMap}}
\logpage{[ 7, 1, 2 ]}\nobreak
\hyperdef{L}{X7FC1C1CD87229F1B}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{HashMap({\mdseries\slshape [values][,] [hashfunc[, eqfunc]][,] [capacity]})\index{HashMap@\texttt{HashMap}}
\label{HashMap}
}\hfill{\scriptsize (function)}}\\


 Create a new hash map. The optional argument \mbox{\texttt{\mdseries\slshape values}} must be a list of key\texttt{\symbol{45}}value pairs which will be inserted
into the new hashmap in order. The optional argument \mbox{\texttt{\mdseries\slshape hashfunc}} must be a hash\texttt{\symbol{45}}function, \mbox{\texttt{\mdseries\slshape eqfunc}} must be a binary equality testing function that returns \texttt{true} if the two arguments are considered equal, and \texttt{false} if they are not. Refer to Chapter \ref{Chapter_HashFunctions} about the requirements for hashfunctions and equality testers. The optional
argument \mbox{\texttt{\mdseries\slshape capacity}} determines the initial size of the hashmap. 

 }

 

\subsection{\textcolor{Chapter }{Keys (for IsHashMap)}}
\logpage{[ 7, 1, 3 ]}\nobreak
\hyperdef{L}{X827F974B7B5111CA}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Keys({\mdseries\slshape h})\index{Keys@\texttt{Keys}!for IsHashMap}
\label{Keys:for IsHashMap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
a list 



 Returns the list of keys of the hashmap \mbox{\texttt{\mdseries\slshape h}}. }

 

\subsection{\textcolor{Chapter }{Values (for IsHashMap)}}
\logpage{[ 7, 1, 4 ]}\nobreak
\hyperdef{L}{X7B774EB27F2B7148}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Values({\mdseries\slshape h})\index{Values@\texttt{Values}!for IsHashMap}
\label{Values:for IsHashMap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
a list 



 Returns the set of values stored in the hashmap \mbox{\texttt{\mdseries\slshape h}}. }

 

\subsection{\textcolor{Chapter }{KeyIterator (for IsHashMap)}}
\logpage{[ 7, 1, 5 ]}\nobreak
\hyperdef{L}{X820C9185827968FA}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{KeyIterator({\mdseries\slshape h})\index{KeyIterator@\texttt{KeyIterator}!for IsHashMap}
\label{KeyIterator:for IsHashMap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an iterator 



 Returns an iterator for the keys stored in the hashmap \mbox{\texttt{\mdseries\slshape h}}. }

 

\subsection{\textcolor{Chapter }{ValueIterator (for IsHashMap)}}
\logpage{[ 7, 1, 6 ]}\nobreak
\hyperdef{L}{X7B4D76A47B09C173}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{ValueIterator({\mdseries\slshape h})\index{ValueIterator@\texttt{ValueIterator}!for IsHashMap}
\label{ValueIterator:for IsHashMap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an iterator 



 Returns an iterator for the values stored in the hashmap \mbox{\texttt{\mdseries\slshape h}}. }

 

\subsection{\textcolor{Chapter }{KeyValueIterator (for IsHashMap)}}
\logpage{[ 7, 1, 7 ]}\nobreak
\hyperdef{L}{X7F75A43984B05E73}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{KeyValueIterator({\mdseries\slshape h})\index{KeyValueIterator@\texttt{KeyValueIterator}!for IsHashMap}
\label{KeyValueIterator:for IsHashMap}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an iterator 



 Returns an iterator for key\texttt{\symbol{45}}value\texttt{\symbol{45}}pairs
stored in the hashmap \mbox{\texttt{\mdseries\slshape h}}. }

 

\subsection{\textcolor{Chapter }{\texttt{\symbol{92}}[\texttt{\symbol{92}}] (for IsHashMapRep, IsObject)}}
\logpage{[ 7, 1, 8 ]}\nobreak
\hyperdef{L}{X818E60167B0B12F7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{\texttt{\symbol{92}}[\texttt{\symbol{92}}]({\mdseries\slshape hashmap, object})\index{\texttt{\symbol{92}}[\texttt{\symbol{92}}]@\texttt{\texttt{\symbol{92}}[\texttt{\symbol{92}}]}!for IsHashMapRep, IsObject}
\label{bSlash[bSlash]:for IsHashMapRep, IsObject}
}\hfill{\scriptsize (operation)}}\\


 List\texttt{\symbol{45}}style access for hashmaps. }

 

\subsection{\textcolor{Chapter }{\texttt{\symbol{92}}[\texttt{\symbol{92}}]\texttt{\symbol{92}}:\texttt{\symbol{92}}= (for IsHashMapRep, IsObject, IsObject)}}
\logpage{[ 7, 1, 9 ]}\nobreak
\hyperdef{L}{X8028C04B7895B9CD}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{\texttt{\symbol{92}}[\texttt{\symbol{92}}]\texttt{\symbol{92}}:\texttt{\symbol{92}}=({\mdseries\slshape hashmap, object, object})\index{\texttt{\symbol{92}}[\texttt{\symbol{92}}]\texttt{\symbol{92}}:\texttt{\symbol{92}}=@\texttt{\texttt{\symbol{92}}[\texttt{\symbol{92}}]\texttt{\symbol{92}}:\texttt{\symbol{92}}=}!for IsHashMapRep, IsObject, IsObject}
\label{bSlash[bSlash]bSlash:bSlash=:for IsHashMapRep, IsObject, IsObject}
}\hfill{\scriptsize (operation)}}\\


 List\texttt{\symbol{45}}style assignment for hashmaps. }

 

\subsection{\textcolor{Chapter }{\texttt{\symbol{92}}in (for IsObject, IsHashMapRep)}}
\logpage{[ 7, 1, 10 ]}\nobreak
\hyperdef{L}{X78DF0E377A70207E}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{\texttt{\symbol{92}}in({\mdseries\slshape object, hashmap})\index{\texttt{\symbol{92}}in@\texttt{\texttt{\symbol{92}}in}!for IsObject, IsHashMapRep}
\label{bSlashin:for IsObject, IsHashMapRep}
}\hfill{\scriptsize (operation)}}\\


 Test whether a key is stored in the hashmap. }

 

\subsection{\textcolor{Chapter }{IsBound\texttt{\symbol{92}}[\texttt{\symbol{92}}] (for IsHashMapRep, IsObject)}}
\logpage{[ 7, 1, 11 ]}\nobreak
\hyperdef{L}{X84CD9B0B82DC85F7}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsBound\texttt{\symbol{92}}[\texttt{\symbol{92}}]({\mdseries\slshape object, hashmap})\index{IsBound\texttt{\symbol{92}}[\texttt{\symbol{92}}]@\texttt{IsBound\texttt{\symbol{92}}[\texttt{\symbol{92}}]}!for IsHashMapRep, IsObject}
\label{IsBoundbSlash[bSlash]:for IsHashMapRep, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Test whether a key is stored in the hashmap. }

 

\subsection{\textcolor{Chapter }{Unbind\texttt{\symbol{92}}[\texttt{\symbol{92}}] (for IsHashMapRep, IsObject)}}
\logpage{[ 7, 1, 12 ]}\nobreak
\hyperdef{L}{X85A876A479D7161D}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Unbind\texttt{\symbol{92}}[\texttt{\symbol{92}}]({\mdseries\slshape object, hashmap})\index{Unbind\texttt{\symbol{92}}[\texttt{\symbol{92}}]@\texttt{Unbind\texttt{\symbol{92}}[\texttt{\symbol{92}}]}!for IsHashMapRep, IsObject}
\label{UnbindbSlash[bSlash]:for IsHashMapRep, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Delete a key from a hashmap. }

 

\subsection{\textcolor{Chapter }{Size (for IsHashMapRep)}}
\logpage{[ 7, 1, 13 ]}\nobreak
\hyperdef{L}{X866A89F080CE944A}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Size({\mdseries\slshape hashmap})\index{Size@\texttt{Size}!for IsHashMapRep}
\label{Size:for IsHashMapRep}
}\hfill{\scriptsize (operation)}}\\


 Determine the number of keys stored in a hashmap. }

 

\subsection{\textcolor{Chapter }{IsEmpty (for IsHashMapRep)}}
\logpage{[ 7, 1, 14 ]}\nobreak
\hyperdef{L}{X857102527A38A649}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsEmpty({\mdseries\slshape object, hashmap})\index{IsEmpty@\texttt{IsEmpty}!for IsHashMapRep}
\label{IsEmpty:for IsHashMapRep}
}\hfill{\scriptsize (operation)}}\\


 Test whether a hashmap is empty. }

 }

 }

   
\chapter{\textcolor{Chapter }{Hashsets}}\label{Chapter_Hashsets}
\logpage{[ 8, 0, 0 ]}
\hyperdef{L}{X80589F287F1620B2}{}
{
  

 A hash set stores objects and allows efficient lookup whether an object is
already a member of the set. 

 \textsf{datastructures} currently provides a reference implementation of hashsets using a hashtable
stored in a plain \textsf{GAP} list. 
\section{\textcolor{Chapter }{API}}\label{Chapter_Hashsets_Section_API}
\logpage{[ 8, 1, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 

\subsection{\textcolor{Chapter }{IsHashSet (for IsObject and IsFinite)}}
\logpage{[ 8, 1, 1 ]}\nobreak
\hyperdef{L}{X81FA1C7B84314DAF}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsHashSet({\mdseries\slshape arg})\index{IsHashSet@\texttt{IsHashSet}!for IsObject and IsFinite}
\label{IsHashSet:for IsObject and IsFinite}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 Category of hashsets }

 

\subsection{\textcolor{Chapter }{HashSet}}
\logpage{[ 8, 1, 2 ]}\nobreak
\hyperdef{L}{X789A593B7C227BE5}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{HashSet({\mdseries\slshape [values][,] [hashfunc[, eqfunc]][,] [capacity]})\index{HashSet@\texttt{HashSet}}
\label{HashSet}
}\hfill{\scriptsize (function)}}\\


 Create a new hashset. The optional argument \mbox{\texttt{\mdseries\slshape values}} must be a list of values, which will be inserted into the new hashset in
order. The optional argument \mbox{\texttt{\mdseries\slshape hashfunc}} must be a hash\texttt{\symbol{45}} function, \mbox{\texttt{\mdseries\slshape eqfunc}} must be a binary equality testing function that returns \texttt{true} if the two arguments are considered equal, and \texttt{false} if they are not. Refer to Chapter \ref{Chapter_HashFunctions} about the requirements for hashfunctions and equality testers. The optional
argument \mbox{\texttt{\mdseries\slshape capacity}} determines the initial size of the hashmap. 

 }

 

\subsection{\textcolor{Chapter }{AddSet (for IsHashSetRep, IsObject)}}
\logpage{[ 8, 1, 3 ]}\nobreak
\hyperdef{L}{X7C7FBBE27E833BB3}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{AddSet({\mdseries\slshape hashset, obj})\index{AddSet@\texttt{AddSet}!for IsHashSetRep, IsObject}
\label{AddSet:for IsHashSetRep, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Add \mbox{\texttt{\mdseries\slshape obj}} to \mbox{\texttt{\mdseries\slshape hashset}}. }

 

\subsection{\textcolor{Chapter }{\texttt{\symbol{92}}in (for IsObject, IsHashSetRep)}}
\logpage{[ 8, 1, 4 ]}\nobreak
\hyperdef{L}{X7CECEB107D9B8645}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{\texttt{\symbol{92}}in({\mdseries\slshape obj, hashset})\index{\texttt{\symbol{92}}in@\texttt{\texttt{\symbol{92}}in}!for IsObject, IsHashSetRep}
\label{bSlashin:for IsObject, IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\


 Test membership of \mbox{\texttt{\mdseries\slshape obj}} in \mbox{\texttt{\mdseries\slshape hashset}} }

 

\subsection{\textcolor{Chapter }{RemoveSet (for IsHashSetRep, IsObject)}}
\logpage{[ 8, 1, 5 ]}\nobreak
\hyperdef{L}{X80E770C2845B4155}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{RemoveSet({\mdseries\slshape hashset, obj})\index{RemoveSet@\texttt{RemoveSet}!for IsHashSetRep, IsObject}
\label{RemoveSet:for IsHashSetRep, IsObject}
}\hfill{\scriptsize (operation)}}\\


 Remove \mbox{\texttt{\mdseries\slshape obj}} from \mbox{\texttt{\mdseries\slshape hashset}}. }

 

\subsection{\textcolor{Chapter }{Size (for IsHashSetRep)}}
\logpage{[ 8, 1, 6 ]}\nobreak
\hyperdef{L}{X82596CD77B2EC7C5}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Size({\mdseries\slshape hashset})\index{Size@\texttt{Size}!for IsHashSetRep}
\label{Size:for IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\


 Return the size of a hashset Returns an integer }

 

\subsection{\textcolor{Chapter }{IsEmpty (for IsHashSetRep)}}
\logpage{[ 8, 1, 7 ]}\nobreak
\hyperdef{L}{X8142E775878A1A6E}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsEmpty({\mdseries\slshape hashset})\index{IsEmpty@\texttt{IsEmpty}!for IsHashSetRep}
\label{IsEmpty:for IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
a boolean 



 Test a hashset for emptiness. }

 

\subsection{\textcolor{Chapter }{Set (for IsHashSetRep)}}
\logpage{[ 8, 1, 8 ]}\nobreak
\hyperdef{L}{X7D1EE80687CAB426}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Set({\mdseries\slshape hashset})\index{Set@\texttt{Set}!for IsHashSetRep}
\label{Set:for IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
a set 



 Convert a hashset into a \textsf{GAP} set }

 

\subsection{\textcolor{Chapter }{AsSet (for IsHashSetRep)}}
\logpage{[ 8, 1, 9 ]}\nobreak
\hyperdef{L}{X835176CB8124AF70}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{AsSet({\mdseries\slshape hashset})\index{AsSet@\texttt{AsSet}!for IsHashSetRep}
\label{AsSet:for IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an immutable set 



 Convert a hashset into a \textsf{GAP} set }

 

\subsection{\textcolor{Chapter }{Iterator (for IsHashSetRep)}}
\logpage{[ 8, 1, 10 ]}\nobreak
\hyperdef{L}{X792F44027D8C73DA}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Iterator({\mdseries\slshape set})\index{Iterator@\texttt{Iterator}!for IsHashSetRep}
\label{Iterator:for IsHashSetRep}
}\hfill{\scriptsize (operation)}}\\
\textbf{\indent Returns:}
an iterator 



 Create an iterator for the values contained in a hashset. Note that elements
added to the hashset after the creation of an iterator are not guaranteed to
be returned by that iterator. }

 }

 }

   
\chapter{\textcolor{Chapter }{Memoisation}}\label{Chapter_Memoisation}
\logpage{[ 9, 0, 0 ]}
\hyperdef{L}{X8693FF6287BAAB84}{}
{
  

 \textsf{datastructures} provides simple ways to cache return values of pure functions. 

 
\section{\textcolor{Chapter }{Memoisation with HashMap}}\label{Chapter_Memoisation_Section_Memoisation_with_HashMap}
\logpage{[ 9, 1, 0 ]}
\hyperdef{L}{X8779C9D987C7B094}{}
{
  

 

\subsection{\textcolor{Chapter }{MemoizeFunction}}
\logpage{[ 9, 1, 1 ]}\nobreak
\hyperdef{L}{X7E7224D77AFAFE00}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{MemoizeFunction({\mdseries\slshape function[, options]})\index{MemoizeFunction@\texttt{MemoizeFunction}}
\label{MemoizeFunction}
}\hfill{\scriptsize (function)}}\\
\textbf{\indent Returns:}
A function 



 \texttt{MemoizeFunction} returns a function which behaves the same as \mbox{\texttt{\mdseries\slshape function}}, except that it caches the return value of \mbox{\texttt{\mdseries\slshape function}}. The cache can be flushed by calling \texttt{FlushCaches} (\textbf{Reference: FlushCaches}). 

 This function does not promise to never call \mbox{\texttt{\mdseries\slshape function}} more than once for any input \texttt{\symbol{45}}\texttt{\symbol{45}} values
may be removed if the cache gets too large, or GAP chooses to flush all
caches, or if multiple threads try to calculate the same value simultaneously. 

 The optional second argument is a record which provides a number of
configuration options. The following options are supported. 
\begin{description}
\item[{\texttt{flush} (default \texttt{true})}]  If this is \texttt{true}, the cache is emptied whenever \texttt{FlushCaches} (\textbf{Reference: FlushCaches}) is called. 
\item[{\texttt{contract} (defaults to \texttt{ReturnTrue} (\textbf{Reference: ReturnTrue}))}]  A function that is called on the arguments given to \mbox{\texttt{\mdseries\slshape function}}. If this function returns \texttt{false}, then \texttt{errorHandler} is called. 
\item[{\texttt{errorHandler} (defaults to none)}]  A function to be called when an input that does not fulfil \texttt{contract} is passed to the cache. 
\end{description}
 

 }

 }

 }

   
\chapter{\textcolor{Chapter }{Ordered Set Datastructures}}\label{Chapter_Ordered_Set_Datastructures}
\logpage{[ 10, 0, 0 ]}
\hyperdef{L}{X8134174379D8CD1E}{}
{
  

 In this chapter we deal with datastructures designed to represent sets of
objects which have an intrinsic ordering. Such datastructures should support
fast (possibly amortised) $O(\log n)$ addition, deletion and membership test operations and allow efficient
iteration through all the objects in the datastructure in the order determined
by the given comparison function. Since they represent a set, adding an object
equal to one already present has no effect. 

 We refer to these as ordered set \emph{datastructure} because the differ from the \textsf{GAP} notion of a set in a number of ways: 
\begin{itemize}
\item  They all lie in a common family \texttt{OrderedSetDSFamily} and pay no attention to the families of the objects stored in them. 
\item  Equality of these structures is by identity, not equality of the represented
set 
\item  The ordering of the objects in the set does not have to be default \textsf{GAP} ordering "less than", but is determined by the attribute \texttt{LessFunction} (\ref{LessFunction:for IsOrderedSetDS}) 
\end{itemize}
 

 Three implementations of ordered set data structures are currently included:
skiplists, binary search trees and (as a specialisation of binary search
trees) AVL trees. AVL trees seem to be the fastest in general, and memory
usage is similar. More details to come 
\section{\textcolor{Chapter }{Usage}}\label{Chapter_Ordered_Set_Datastructures_Section_Usage}
\logpage{[ 10, 1, 0 ]}
\hyperdef{L}{X86A9B6F87E619FFF}{}
{
  

 
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
  !gapprompt@gap>| !gapinput@s := OrderedSetDS(IsSkipListRep, {x,y} -> String(x) < String(y));|
  <skiplist 0 entries>
  !gapprompt@gap>| !gapinput@Addset(s, 1);|
  !gapprompt@gap>| !gapinput@AddSet(s, 2);|
  !gapprompt@gap>| !gapinput@AddSet(s, 10);|
  !gapprompt@gap>| !gapinput@AddSet(s, (1,2,3));|
  !gapprompt@gap>| !gapinput@RemoveSet(s, (1,2,3));|
  1
  !gapprompt@gap>| !gapinput@AsListSorted(s);|
  [ 1, 10, 2 ]
  
  !gapprompt@gap>| !gapinput@b := OrderedSetDS(IsBinarySearchTreeRep, Primes);|
  <bst size 168>
  !gapprompt@gap>| !gapinput@91 in b;|
  false
  !gapprompt@gap>| !gapinput@97 in b;|
  true
\end{Verbatim}
 }

 
\section{\textcolor{Chapter }{API}}\label{Chapter_Ordered_Set_Datastructures_Section_API}
\logpage{[ 10, 2, 0 ]}
\hyperdef{L}{X7C5F33687C53BEF0}{}
{
  

 Every implementation of an ordered set datastructure must follow the API set
out below 

 

\subsection{\textcolor{Chapter }{IsOrderedSetDS (for IsObject)}}
\logpage{[ 10, 2, 1 ]}\nobreak
\hyperdef{L}{X829BF6468120FCF4}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsOrderedSetDS({\mdseries\slshape arg})\index{IsOrderedSetDS@\texttt{IsOrderedSetDS}!for IsObject}
\label{IsOrderedSetDS:for IsObject}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 Category of ordered set. }

 

\subsection{\textcolor{Chapter }{IsStandardOrderedSetDS (for IsOrderedSetDS)}}
\logpage{[ 10, 2, 2 ]}\nobreak
\hyperdef{L}{X83DF983D824ADA52}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{IsStandardOrderedSetDS({\mdseries\slshape arg})\index{IsStandardOrderedSetDS@\texttt{IsStandardOrderedSetDS}!for IsOrderedSetDS}
\label{IsStandardOrderedSetDS:for IsOrderedSetDS}
}\hfill{\scriptsize (filter)}}\\
\textbf{\indent Returns:}
\texttt{true} or \texttt{false} 



 Subcategory of ordered sets where the ordering is \textsf{GAP}'s default \texttt{{\textless}} }

 

\subsection{\textcolor{Chapter }{OrderedSetDS (for IsOrderedSetDS, IsFunction, IsListOrCollection, IsRandomSource)}}
\logpage{[ 10, 2, 3 ]}\nobreak
\hyperdef{L}{X7C0A0ACD833B09E8}{}
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{OrderedSetDS({\mdseries\slshape filter[, lessThan[, initialEntries[, randomSource]]]})\index{OrderedSetDS@\texttt{OrderedSetDS}!for IsOrderedSetDS, IsFunction, IsListOrCollection, IsRandomSource}
\label{OrderedSetDS:for IsOrderedSetDS, IsFunction, IsListOrCollection, IsRandomSource}
}\hfill{\scriptsize (constructor)}}\\
\textbf{\indent Returns:}
an ordered set datastructure 



 The family that contains all ordered set datastructures. Constructors for
ordered sets 

 The argument \mbox{\texttt{\mdseries\slshape filter}} is a filter that the resulting ordered set object will have.

 The optional argument \mbox{\texttt{\mdseries\slshape lessThan}} must be a binary function that returns \texttt{true} if its first argument is less than its second argument, and \texttt{false} otherwise. The default \mbox{\texttt{\mdseries\slshape lessThan}} is \textsf{GAP}'s built in \texttt{{\textless}}.

 The optional argument \mbox{\texttt{\mdseries\slshape  initialEntries}} gives a collection of elements that the ordered set is initialised with, and
defaults to the empty set.

 The optional argument \mbox{\texttt{\mdseries\slshape randomSource}} is useful in a number of possible implementations that use randomised methods
to achieve good amortised complexity with high probability and simple data
structures. It defaults to the global Mersenne twister. 

 }

 

\subsection{\textcolor{Chapter }{OrderedSetDS (for IsOrderedSetDS, IsFunction, IsRandomSource)}}
\logpage{[ 10, 2, 4 ]}\nobreak
\hyperdef{L}{X784F06667B9CAE61}{}
--> --------------------

--> maximum size reached

--> --------------------

100%


¤ Dauer der Verarbeitung: 0.68 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.