Skip to content

Commit

Permalink
use rem instead of positiveRemainder
Browse files Browse the repository at this point in the history
  • Loading branch information
hemmecke committed Dec 22, 2024
1 parent 16b0086 commit 1a7932d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-12-22 Ralf Hemmecke <[email protected]>

* src/algebra/xhash.spad, src/algebra/hashstate.spad: use rem
instead of positiveRemainder

2024-12-20 Waldek Hebisch <[email protected]>

* src/interp/br-con.boot, src/interp/br-op1.boot,
Expand Down
3 changes: 2 additions & 1 deletion src/algebra/hashstate.spad
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ HashState() : with
++ update!(hs, x) computes new values of HashState from hs
++ and x and might destructively operate on its first argument.
value : % -> SingleInteger
++ value(x) returns a SingleInteger value corresponding to x.
++ value(x) returns a non-negative SingleInteger value
++ corresponding to x.
== add
-- These two macros are necessary to distinguish between Rep and \%.
rep x ==> (x@%) pretend Rep
Expand Down
21 changes: 7 additions & 14 deletions src/algebra/xhash.spad
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
)abbrev domain XHASHTBL XHashTable
)if LiterateDoc
\documentclass{article}
\usepackage{url}
\usepackage{color}
\definecolor{bgcode}{rgb}{1,1,0.7}

\usepackage{listings}
\lstdefinelanguage{spad}{basicstyle=\footnotesize\ttfamily,%
numbers=left,firstnumber=last,backgroundcolor=\color{bgcode}}
\parindent0pt
\parskip\medskipamount

\usepackage{literatedoc}
\begin{document}
\title{A hash table implementation via double hashing}
\author{Ralf Hemmecke}
Expand Down Expand Up @@ -45,7 +36,7 @@ respectively. \texttt{VACANT} and \texttt{DELETED} should not be part
of the key space.

Let's assume that the type of the marker values is \texttt{Marker}.
Naively, and type correctly, we would have to use as representation
Naively, and type correctly, we would have to use a representation
like the following.
\begin{verbatim}
Union(Marker, Record(key: Key, entry: Entry))
Expand Down Expand Up @@ -111,6 +102,8 @@ XHashTable(Key: Hashable, Entry: Type):
++ the sense that from k1=k2 follows h(k1)=h(k2). If that is not
++ the case, k1 and k2 will internally be considered as being
++ different keys.
++ For XHashTable to work correctly, the function h must only
++ yield non-negative values.
== add
KE ==> Record(key: Key, entry: Entry)
UE ==> Union(Entry, "failed")
Expand Down Expand Up @@ -341,9 +334,9 @@ stored and thus the loops eventually terminate.
mk := getMKey(a, p)

n: Z := numOfBuckets a
h1: Z := (h k)::Z
p: Z := positiveRemainder(h1, n) -- position in array
h2: Z := 1 + positiveRemainder(h1, n-2)
h1: Z := (h k)::Z -- h1>=0
p: Z := h1 rem n -- position in array (p>=0)
h2: Z := 1 + (h1 rem (n-2)) -- h2>=0
mk: MKey := getMKey(a, p)
deletedPosition?: Boolean := false
while not vacant? mk repeat
Expand Down

0 comments on commit 1a7932d

Please sign in to comment.