Skip to content

Commit

Permalink
Add default IsBound on small lists for large integers
Browse files Browse the repository at this point in the history
This provides an implementation of IsBound for arguments which
are too large to be a list index for various list types,
including non-dense lists and atomic lists
  • Loading branch information
ChrisJefferson authored and wilfwilson committed Dec 5, 2019
1 parent 8e1e35d commit e6d5121
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,20 @@ InstallMethod( IsBound\[\],
return index <= Length( list );
end );

#############################################################################
##
#M IsBound( list[i] ) . . . . . IsBound for small lists with large arguments
##
InstallMethod( IsBound\[\],
"for a small list and large positive integer",
[ IsSmallList, IsPosInt ],
function( list, index )
if IsSmallIntRep(index) then
TryNextMethod();
else
return false;
fi;
end );

#############################################################################
##
Expand Down
2 changes: 2 additions & 0 deletions tst/testinstall/hpc/atomic_list.tst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ gap> IsBound(a[3]);
false
gap> IsBound(a[9]);
false
gap> IsBound(a[2^100]);
false
gap> GetWithDefault(a, 2, -1);
7
gap> GetWithDefault(a, 3, -1);
Expand Down
11 changes: 11 additions & 0 deletions tst/testinstall/list.tst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ gap> Unbind(a[1,1,1]);
Syntax error: '[]' only supports 1 or 2 indices in stream:1
Unbind(a[1,1,1]);
^
gap> a := [1,,3];;
gap> IsBound(a[1]);
true
gap> IsBound(a[2]);
false
gap> IsBound(a[3]);
true
gap> IsBound(a[4]);
false
gap> IsBound(a[2^100]);
false

#
# slices
Expand Down

0 comments on commit e6d5121

Please sign in to comment.