diff --git a/doc/clean b/doc/clean index 9a8d06f..b312721 100755 --- a/doc/clean +++ b/doc/clean @@ -1,3 +1,4 @@ -#!/bin/bash +#!/bin/sh + rm -f *.{aux,lab,log,dvi,ps,pdf,bbl,ilg,ind,idx,out,html,tex,pnr,txt,blg,toc,six,brf} diff --git a/gap/binaryheap.gi b/gap/binaryheap.gi index 1ce40cd..a9d3fd3 100644 --- a/gap/binaryheap.gi +++ b/gap/binaryheap.gi @@ -50,12 +50,12 @@ end); InstallMethod(Push, "for a binary heap in plain representation", - [IsBinaryHeapFlatRep, IsObject], + [IsBinaryHeapFlatRep and IsMutable, IsObject], DS_BinaryHeap_Insert); InstallMethod(Pop, "for a binary heap in plain representation", - [IsBinaryHeapFlatRep], + [IsBinaryHeapFlatRep and IsMutable], function(heap) local val, data; data := heap![2]; @@ -98,3 +98,9 @@ function(heap) Print(""); end); +InstallMethod(PostMakeImmutable, + "for a bineary heap", + [ IsBinaryHeapFlatRep ], +function(heap) + MakeImmutable(heap![2]); +end); diff --git a/gap/hashmap.gi b/gap/hashmap.gi index ec6e3fa..d6106c5 100644 --- a/gap/hashmap.gi +++ b/gap/hashmap.gi @@ -50,7 +50,7 @@ InstallOtherMethod(\[\], InstallOtherMethod(\[\]\:\=, "for a hash map, a key and a value", - [ IsHashMapRep, IsObject, IsObject ], + [ IsHashMapRep and IsMutable, IsObject, IsObject ], DS_Hash_SetValue); InstallOtherMethod( \in, @@ -65,7 +65,7 @@ InstallOtherMethod( IsBound\[\], InstallOtherMethod( Unbind\[\], "for a hash map and a key", - [ IsHashMapRep, IsObject ], + [ IsHashMapRep and IsMutable, IsObject ], DS_Hash_Delete); InstallOtherMethod( Size, @@ -77,3 +77,11 @@ InstallOtherMethod( IsEmpty, "for a hash map", [ IsHashMapRep ], ht -> DS_Hash_Used(ht) = 0); + +InstallMethod( PostMakeImmutable, + "for a hash map", + [ IsHashMapRep ], +function(ht) + MakeImmutable(ht![5]); + MakeImmutable(ht![6]); +end); diff --git a/gap/pairingheap.gd b/gap/pairingheap.gd index 44d6611..6513c48 100644 --- a/gap/pairingheap.gd +++ b/gap/pairingheap.gd @@ -13,9 +13,7 @@ ## DeclareRepresentation( "IsPairingHeapFlatRep", IsHeap and IsPositionalObjectRep, []); -BindGlobal( "PairingHeapType", NewType(HeapFamily, IsPairingHeapFlatRep)); -BindGlobal( "PairingHeapTypeMutable", NewType(HeapFamily, - IsPairingHeapFlatRep and IsMutable)); +BindGlobal( "PairingHeapType", NewType(HeapFamily, IsPairingHeapFlatRep and IsMutable)); DeclareGlobalFunction("PairingHeap"); DeclareGlobalFunction("PairingHeapPush"); diff --git a/gap/pairingheap.gi b/gap/pairingheap.gi index d7386b8..018e879 100644 --- a/gap/pairingheap.gi +++ b/gap/pairingheap.gi @@ -54,7 +54,7 @@ function(arg...) # node[1] data # node[2] number of nodes in the subheap # node[3] list of subheaps - heap := Objectify(PairingHeapTypeMutable, [0, isLess, []]); + heap := Objectify(PairingHeapType, [0, isLess, []]); for x in data do PairingHeapPush(heap, x); @@ -99,12 +99,12 @@ end); InstallMethod(Push , "for a pairing heap in plain representation, and data" - , [IsPairingHeapFlatRep, IsObject] + , [IsPairingHeapFlatRep and IsMutable, IsObject] , PairingHeapPush); InstallMethod(Pop , "for a pairing heap in plain representation" - , [IsPairingHeapFlatRep] + , [IsPairingHeapFlatRep and IsMutable] , PairingHeapPop); InstallMethod(Peek @@ -122,11 +122,18 @@ InstallOtherMethod(IsEmpty , [IsPairingHeapFlatRep] , h -> h![1] = 0); -InstallMethod( ViewObj, +InstallMethod(ViewObj, "for a pairing heap in flat representation", - [ IsPairingHeapFlatRep ], + [IsPairingHeapFlatRep], function(h) Print(""); end); + +InstallMethod(PostMakeImmutable, + "for a pairing heap", + [ IsPairingHeapFlatRep ], +function(h) + MakeImmutable(h![3]); +end); diff --git a/gap/plistdeque.gi b/gap/plistdeque.gi index ad0162d..e7887d6 100644 --- a/gap/plistdeque.gi +++ b/gap/plistdeque.gi @@ -13,10 +13,11 @@ # # The four positions in a deque Q have the following purpose # -# Q[1] - head, the index in Q[4] of the first element in the deque -# Q[2] - tail, the index in Q[4] of the last element in the deque +# Q[1] - head, the index in Q[5] of the first element in the deque +# Q[2] - tail, the index in Q[5] of the last element in the deque # Q[3] - capacity, the allocated capacity in the deque -# Q[4] - GAP plain list with storage for capacity many entries +# Q[4] - FIXME: describe QFACTOR ... +# Q[5] - GAP plain list with storage for capacity many entries # # Global variables QHEAD, QTAIL, QCAPACITY, and QDATA are bound to reflect # the above. @@ -230,34 +231,24 @@ end); InstallMethod(PushBack, "for IsPlistDeque and an object", - [IsPlistDequeRep, IsObject], + [IsPlistDequeRep and IsMutable, IsObject], PlistDequePushBack); InstallMethod(PushFront, "for IsPlistDeque and an object", - [IsPlistDequeRep, IsObject], + [IsPlistDequeRep and IsMutable, IsObject], PlistDequePushFront); -InstallMethod(Push, - "for IsPlistDeque and an object", - [IsPlistDequeRep, IsObject], - PlistDequePushBack); - InstallMethod(PopFront, "for IsPlistDeque and an object", - [IsPlistDequeRep], + [IsPlistDequeRep and IsMutable], PlistDequePopFront); InstallMethod(PopBack, "for IsPlistDeque and an object", - [IsPlistDequeRep], + [IsPlistDequeRep and IsMutable], PlistDequePopBack); -InstallMethod(Pop, - "for IsPlistDeque and an object", - [IsPlistDequeRep], - PlistDequePopFront); - InstallOtherMethod(IsEmpty, "for IsPlistDeque", [IsPlistDequeRep], @@ -293,11 +284,18 @@ function(deque) return deque![QCAPACITY]; end); -InstallMethod( ViewObj, - "for a PlistDeque", - [ IsPlistDequeRep ], +InstallMethod(ViewObj, + "for IsPlistDeque", + [IsPlistDequeRep], function(deque) Print(""); end); + +InstallMethod(PostMakeImmutable, + "for IsPlistDeque", + [IsPlistDequeRep], +function(deque) + MakeImmutable(deque![QDATA]); +end); diff --git a/gap/queue.gi b/gap/queue.gi new file mode 100644 index 0000000..9a524b9 --- /dev/null +++ b/gap/queue.gi @@ -0,0 +1,10 @@ + +InstallMethod(Push, + "for a queue and an object", + [IsQueue and IsMutable, IsObject], + PushBack); + +InstallMethod(Pop, + "for a queue and an object", + [IsQueue and IsMutable], + PopFront); diff --git a/gap/stack.gd b/gap/stack.gd index 442ee50..1feaa55 100644 --- a/gap/stack.gd +++ b/gap/stack.gd @@ -43,9 +43,7 @@ DeclareOperation("Pop", [IsStack]); # DeclareRepresentation( "IsStackPlistRep", IsStack and IsPositionalObjectRep, []); -BindGlobal( "StackType", NewType(StackFamily, IsStackPlistRep)); -BindGlobal( "StackTypeMutable", NewType(StackFamily, - IsStackPlistRep and IsMutable)); +BindGlobal( "StackType", NewType(StackFamily, IsStackPlistRep and IsMutable)); DeclareGlobalFunction("Stack"); diff --git a/gap/stack.gi b/gap/stack.gi index 470c311..2d20d8a 100644 --- a/gap/stack.gi +++ b/gap/stack.gi @@ -15,12 +15,12 @@ InstallGlobalFunction(Stack, function() - return Objectify(StackTypeMutable, [ [] ]); + return Objectify(StackType, [ [] ]); end); InstallMethod(Push , "for a stack" - , [IsStack, IsObject], + , [IsStack and IsMutable, IsObject], function(s,o) Add(s![1], o); end); @@ -34,7 +34,7 @@ end); InstallMethod(Pop , "for a stack" - , [IsStack], + , [IsStack and IsMutable], function(s) if Length(s![1]) > 0 then return Remove(s![1]); @@ -55,3 +55,9 @@ function(s) Print(""); end); +InstallMethod(PostMakeImmutable + , "for a stack" + , [IsStack], +function(s) + MakeImmutable(s![1]); +end); diff --git a/read.g b/read.g index 3b85fae..bd9ac71 100644 --- a/read.g +++ b/read.g @@ -16,6 +16,7 @@ DeclareInfoClass( "InfoDataStructures" ); SetInfoLevel( InfoDataStructures, 1 ); +ReadPackage("datastructures", "gap/queue.gi"); ReadPackage("datastructures", "gap/plistdeque.gi"); ReadPackage("datastructures", "gap/heap.gi");