Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement suggestion #199 #200

Merged
merged 5 commits into from Dec 10, 2014
Merged

implement suggestion #199 #200

merged 5 commits into from Dec 10, 2014

Conversation

@pzinn
Copy link
Contributor

pzinn commented Dec 1, 2014

Tentative pull. functional, with doc and test.

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.

Copy link
@DanGrayson

DanGrayson Dec 5, 2014

Member

The usage line here doesn't match the method being documented.

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.

Copy link
@DanGrayson

DanGrayson Dec 5, 2014

Member

I suggest we remove this line and the similar one in mapkeys now.

storeInHashTable(x,newkey,h,t);
)
)
else (

This comment has been minimized.

Copy link
@DanGrayson

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.

Copy link
@DanGrayson

DanGrayson Dec 5, 2014

Member

Let's document the effect of "continue" here.

This comment has been minimized.

Copy link
@pzinn

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.

Copy link
@DanGrayson

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.

@pzinn

This comment has been minimized.

Copy link
Contributor Author

pzinn commented Dec 7, 2014

all right, second attempt.

@DanGrayson DanGrayson merged commit 93e6f95 into Macaulay2:master Dec 10, 2014
@DanGrayson

This comment has been minimized.

Copy link
Member

DanGrayson commented Dec 10, 2014

Thanks, Paul, that's a useful change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.