1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#############################################################################
##
#W weakptr.tst GAP Library Steve Linton
##
##
#Y Copyright (C) 1997,
##
##
gap> START_TEST("weakptr.tst");
#
# Low level access functions
#
gap> w := WeakPointerObj([1,,2^40*10^10,Z(17),[2,3,4],fail,SymmetricGroup(5),]);;
gap> Print(w,"\n");
WeakPointerObj( [ 1, , 10995116277760000000000, Z(17),
[ 2, 3, 4 ], fail, SymmetricGroup( [ 1 .. 5 ] ) ] )
gap> IsWeakPointerObject(w);
true
gap> IsWeakPointerObject([1, 2, 3]);
false
gap> LengthWPObj(w);
7
gap> val := "cheese";;
gap> GetWithDefault(w, 1, "cheese");
1
gap> IsIdenticalObj(val, GetWithDefault(w, 2, val));
true
gap> IsIdenticalObj(val, GetWithDefault(w, 8, val));
true
gap> List([1..7],x->IsBoundElmWPObj(w,x));
[ true, false, true, true, true, true, true ]
gap> List([1..7],x->ElmWPObj(w,x));
[ 1, fail, 10995116277760000000000, Z(17), [ 2, 3, 4 ], fail,
Sym( [ 1 .. 5 ] ) ]
gap> SetElmWPObj(w,9,[]);
gap> Print(w,"\n");
WeakPointerObj( [ 1, , 10995116277760000000000, Z(17),
[ 2, 3, 4 ], fail, SymmetricGroup( [ 1 .. 5 ] ), , [ ] ] )
gap> UnbindElmWPObj(w,4);
gap> Print(w,"\n");
WeakPointerObj( [ 1, , 10995116277760000000000, ,
[ 2, 3, 4 ], fail, SymmetricGroup( [ 1 .. 5 ] ), , [ ] ] )
gap> UnbindElmWPObj(w,9); LengthWPObj(w);
7
gap> 1;;2;;3;;
gap> truevec := [1,,2^40*10^10,(1,5,6),[2,3,4],fail,SymmetricGroup(5),];;
gap> wcopies := List([1..1000], x -> WeakPointerObj([1,,2^40*10^10,(1,5,6),[2,3,4],fail,SymmetricGroup(5),]));;
gap> GASMAN("collect");
gap> ForAll(wcopies, x -> LengthWPObj(x) = 6 or LengthWPObj(x) = 7);
true
gap> ForAny(wcopies, x -> LengthWPObj(x) = 6);
true
gap> ForAll(wcopies, x -> x[1] = 1 and x[6] = fail);
true
gap> ForAll([2,3,4,5,7], x -> ForAny(wcopies, y -> not(IsBound(y[x]))));
true
gap> ForAll([3,4,5,7], x -> ForAny(wcopies, y -> not(IsBound(y[x])) or y[x] = truevec[x]));
true
gap> # Take a filtered list
gap> w := First(wcopies, x -> ForAll([2,3,4,5,7], y -> not(IsBound(x[y])) ) );;
gap> Print(w,"\n");
WeakPointerObj( [ 1, , , , , fail ] )
gap> LengthWPObj(w);
6
gap> Print(ShallowCopy(w),"\n");
WeakPointerObj( [ 1, , , , , fail ] )
gap> List([1..8], x -> GetWithDefault(w, x, -1));
[ 1, -1, -1, -1, -1, fail, -1, -1 ]
gap> GetWithDefault(w, 1, "cheese");
1
gap> IsIdenticalObj(val, GetWithDefault(w, 2, val));
true
gap> IsIdenticalObj(val, GetWithDefault(w, 8, val));
true
#
# Access as lists
#
gap> w[1];
1
gap> l := [ 311 ];; # keep ref so that this list is not garbage collected
gap> w{[2..4]} := [[1,2],E(5),l];
[ [ 1, 2 ], E(5), [ 311 ] ]
gap> Print(w,"\n");
WeakPointerObj( [ 1, [ 1, 2 ], E(5), [ 311 ], , fail ] )
gap> Print(StructuralCopy(w),"\n");
WeakPointerObj( [ 1, [ 1, 2 ], E(5), [ 311 ], , fail ] )
gap> Immutable(w);
[ 1, [ 1, 2 ], E(5), [ 311 ],, fail ]
gap> IsBound(w[2]);
true
gap> GASMAN("collect");
gap> IsBound(w[5]);
false
gap> Unbind(w[2]);
gap> Print(w,"\n");
WeakPointerObj( [ 1, , E(5), [ 311 ], , fail ] )
gap> Immutable(w);
[ 1,, E(5), [ 311 ],, fail ]
gap> w;
WeakPointerObj( [ 1, , E(5), [ 311 ], , fail ] )
gap> MakeImmutable(w);
[ 1,, E(5), [ 311 ],, fail ]
gap> w;
[ 1,, E(5), [ 311 ],, fail ]
gap> IsMutable(w);
false
gap> ForAny(w, IsMutable);
false
#
# test recursive MakeImmutable
#
gap> w := WeakPointerObj([ ~ ]);;
gap> MakeImmutable(w);
[ [ ~[1] ] ]
#
gap> w := WeakPointerObj([ 1 ]);;
gap> w[1] := w;;
gap> MakeImmutable(w);
[ ~ ]
#
gap> w := WeakPointerObj([ rec() ]);;
gap> w[1].self := w;;
gap> MakeImmutable(w);
[ rec( self := ~ ) ]
#
gap> STOP_TEST( "weakptr.tst", 1);
|