Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upimplement suggestion #199 #200
Conversation
document { | ||
Key => (applyKeys,HashTable,Function,Function), | ||
Headline => "apply a function to each key in a hash table with collision handling", | ||
Usage => "applyKeys(H,f)", |
This comment has been minimized.
This comment has been minimized.
while true do ( | ||
if p == p.next then break; | ||
newkey := applyEE(f,p.key); | ||
if newkey == nullE then return buildErrorPacket("null key encountered"); -- remove soon!!! |
This comment has been minimized.
This comment has been minimized.
storeInHashTable(x,newkey,h,t); | ||
) | ||
) | ||
else ( |
This comment has been minimized.
This comment has been minimized.
DanGrayson
Dec 5, 2014
Member
It's hard to read with this else clause not indented the same amount as the line with "if ... then" on it.
if val != notfoundE then ( | ||
t := applyEEE(g,val,p.value); | ||
when t is err:Error do ( | ||
if err.message != continueMessage then return t else remove(x,newkey); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pzinn
Dec 5, 2014
Author
Contributor
I think I got everything covered except the last one. perhaps I'll let you
explain that "continue" statement?
On Fri, Dec 5, 2014 at 1:57 AM, Daniel R. Grayson notifications@github.com
wrote:
In M2/Macaulay2/d/evaluate.d:
+export mapkeysmerge(f:Expr,o:HashTable,g:Expr):Expr := (
x := newHashTable(o.Class,o.parent);
x.beingInitialized = true;
foreach bucket in o.table do (
p := bucket;
while true do (
if p == p.next then break;
newkey := applyEE(f,p.key);
if newkey == nullE then return buildErrorPacket("null key encountered"); -- remove soon!!!
when newkey is Error do return newkey else nothing;
h := hash(newkey);
val := lookup1(x,newkey,h);
if val != notfoundE then (
t := applyEEE(g,val,p.value);
when t is err:Error do (
if err.message != continueMessage then return t else remove(x,newkey);
Let's document the effect of "continue" here.
—
Reply to this email directly or view it on GitHub
https://github.com/Macaulay2/M2/pull/200/files#r21348903.
This comment has been minimized.
This comment has been minimized.
DanGrayson
Dec 5, 2014
Member
It looks to me like you put that line in there so that if "continue" is
executed in the body of the function
handling the collisions, then the result would be a hash table in which the
key doesn't appear. This could be used,
for example, if we are allowing hash tables to represent tallies where the
values are integers, but the value 0, denoting
absence, when encountered, results in absence.
On Thu Dec 04 2014 at 9:55:04 PM Paul Zinn-Justin notifications@github.com
wrote:
In M2/Macaulay2/d/evaluate.d:
+export mapkeysmerge(f:Expr,o:HashTable,g:Expr):Expr := (
x := newHashTable(o.Class,o.parent);
x.beingInitialized = true;
foreach bucket in o.table do (
p := bucket;
while true do (
if p == p.next then break;
newkey := applyEE(f,p.key);
if newkey == nullE then return buildErrorPacket("null key encountered"); -- remove soon!!!
when newkey is Error do return newkey else nothing;
h := hash(newkey);
val := lookup1(x,newkey,h);
if val != notfoundE then (
t := applyEEE(g,val,p.value);
when t is err:Error do (
if err.message != continueMessage then return t else remove(x,newkey);
I think I got everything covered except the last one. perhaps I'll let you
explain that "continue" statement?
… <#msg-f:1486620411913715861_>
On Fri, Dec 5, 2014 at 1:57 AM, Daniel R. Grayson <
notifications@github.com> wrote: In M2/Macaulay2/d/evaluate.d: > +export
mapkeysmerge(f:Expr,o:HashTable,g:Expr):Expr := ( > + x :=
newHashTable(o.Class,o.parent); > + x.beingInitialized = true; > + foreach
bucket in o.table do ( > + p := bucket; > + while true do ( > + if p ==
p.next then break; > + newkey := applyEE(f,p.key); > + if newkey == nullE
then return buildErrorPacket("null key encountered"); -- remove soon!!! > +
when newkey is Error do return newkey else nothing; > + h := hash(newkey);
- val := lookup1(x,newkey,h); > + if val != notfoundE then ( > + t :=
applyEEE(g,val,p.value); > + when t is err:Error do ( > + if err.message !=
continueMessage then return t else remove(x,newkey); Let's document the
effect of "continue" here. — Reply to this email directly or view it on
GitHub https://github.com/Macaulay2/M2/pull/200/files#r21348903.—
Reply to this email directly or view it on GitHub
https://github.com/Macaulay2/M2/pull/200/files#r21354285.
This comment has been minimized.
This comment has been minimized.
all right, second attempt. |
This comment has been minimized.
This comment has been minimized.
Thanks, Paul, that's a useful change! |
pzinn commentedDec 1, 2014
Tentative pull. functional, with doc and test.