From 1667a0b0c6eba68698af63c1a22bcf52782cea14 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 00:53:02 +0200 Subject: [PATCH 1/7] Add generic Push/Pop aliases for queue... ... namely set Push to PushBack, and Pop to PopFront --- gap/plistdeque.gi | 10 ---------- gap/queue.gi | 10 ++++++++++ read.g | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 gap/queue.gi diff --git a/gap/plistdeque.gi b/gap/plistdeque.gi index ad0162d..66d1a19 100644 --- a/gap/plistdeque.gi +++ b/gap/plistdeque.gi @@ -238,11 +238,6 @@ InstallMethod(PushFront, [IsPlistDequeRep, IsObject], PlistDequePushFront); -InstallMethod(Push, - "for IsPlistDeque and an object", - [IsPlistDequeRep, IsObject], - PlistDequePushBack); - InstallMethod(PopFront, "for IsPlistDeque and an object", [IsPlistDequeRep], @@ -253,11 +248,6 @@ InstallMethod(PopBack, [IsPlistDequeRep], PlistDequePopBack); -InstallMethod(Pop, - "for IsPlistDeque and an object", - [IsPlistDequeRep], - PlistDequePopFront); - InstallOtherMethod(IsEmpty, "for IsPlistDeque", [IsPlistDequeRep], 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/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"); From abfdbe07dab09f40f2f671a22496082584ccd29e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 00:54:13 +0200 Subject: [PATCH 2/7] Remove StackTypeMutable and PairingHeapTypeMutable Instead, these types imply "mutable" by default now --- gap/pairingheap.gd | 4 +--- gap/pairingheap.gi | 2 +- gap/stack.gd | 4 +--- gap/stack.gi | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) 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..bc6dbc2 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); 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..73e62de 100644 --- a/gap/stack.gi +++ b/gap/stack.gi @@ -15,7 +15,7 @@ InstallGlobalFunction(Stack, function() - return Objectify(StackTypeMutable, [ [] ]); + return Objectify(StackType, [ [] ]); end); InstallMethod(Push From 16a9cb575260092d77aa0af7470800ac8c6ad3d1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 19:51:01 +0200 Subject: [PATCH 3/7] Add PostMakeImmutable methods --- gap/binaryheap.gi | 6 ++++++ gap/hashmap.gi | 8 ++++++++ gap/pairingheap.gi | 7 +++++++ gap/plistdeque.gi | 7 +++++++ gap/stack.gi | 6 ++++++ 5 files changed, 34 insertions(+) diff --git a/gap/binaryheap.gi b/gap/binaryheap.gi index 1ce40cd..ea7f565 100644 --- a/gap/binaryheap.gi +++ b/gap/binaryheap.gi @@ -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..a1ea108 100644 --- a/gap/hashmap.gi +++ b/gap/hashmap.gi @@ -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.gi b/gap/pairingheap.gi index bc6dbc2..2b2b3b8 100644 --- a/gap/pairingheap.gi +++ b/gap/pairingheap.gi @@ -130,3 +130,10 @@ function(h) , h![1] , " entries>"); 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 66d1a19..e1e9ede 100644 --- a/gap/plistdeque.gi +++ b/gap/plistdeque.gi @@ -291,3 +291,10 @@ function(deque) Print(Size(deque),"/",Capacity(deque)); Print(" entries>"); end); + +InstallMethod(PostMakeImmutable, + "for IsPlistDeque", + [IsPlistDequeRep], +function(deque) + MakeImmutable(deque![QDATA]); +end); diff --git a/gap/stack.gi b/gap/stack.gi index 73e62de..9fb8e14 100644 --- a/gap/stack.gi +++ b/gap/stack.gi @@ -55,3 +55,9 @@ function(s) Print(""); end); +InstallMethod(PostMakeImmutable + , "for a stack" + , [IsStack], +function(s) + MakeImmutable(s![1]); +end); From c31e4bba830394174faf3764f71b2e83f580acd4 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 19:51:25 +0200 Subject: [PATCH 4/7] Add IsMutable to filters for Push/Pop/... operations --- gap/binaryheap.gi | 4 ++-- gap/hashmap.gi | 4 ++-- gap/pairingheap.gi | 4 ++-- gap/plistdeque.gi | 8 ++++---- gap/stack.gi | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gap/binaryheap.gi b/gap/binaryheap.gi index ea7f565..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]; diff --git a/gap/hashmap.gi b/gap/hashmap.gi index a1ea108..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, diff --git a/gap/pairingheap.gi b/gap/pairingheap.gi index 2b2b3b8..15a470d 100644 --- a/gap/pairingheap.gi +++ b/gap/pairingheap.gi @@ -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 diff --git a/gap/plistdeque.gi b/gap/plistdeque.gi index e1e9ede..05778c9 100644 --- a/gap/plistdeque.gi +++ b/gap/plistdeque.gi @@ -230,22 +230,22 @@ 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(PopFront, "for IsPlistDeque and an object", - [IsPlistDequeRep], + [IsPlistDequeRep and IsMutable], PlistDequePopFront); InstallMethod(PopBack, "for IsPlistDeque and an object", - [IsPlistDequeRep], + [IsPlistDequeRep and IsMutable], PlistDequePopBack); InstallOtherMethod(IsEmpty, diff --git a/gap/stack.gi b/gap/stack.gi index 9fb8e14..2d20d8a 100644 --- a/gap/stack.gi +++ b/gap/stack.gi @@ -20,7 +20,7 @@ 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]); From 0a1852c7485ec3be3734f436705c143950e3876b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 19:51:51 +0200 Subject: [PATCH 5/7] Fix shebang in doc/clean --- doc/clean | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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} From fc388621be26c6fabe14ae42d0d47d91ffea42a8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Aug 2017 19:52:04 +0200 Subject: [PATCH 6/7] Code formatting --- gap/pairingheap.gi | 4 ++-- gap/plistdeque.gi | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gap/pairingheap.gi b/gap/pairingheap.gi index 15a470d..018e879 100644 --- a/gap/pairingheap.gi +++ b/gap/pairingheap.gi @@ -122,9 +122,9 @@ InstallOtherMethod(IsEmpty , [IsPairingHeapFlatRep] , h -> h![1] = 0); -InstallMethod( ViewObj, +InstallMethod(ViewObj, "for a pairing heap in flat representation", - [ IsPairingHeapFlatRep ], + [IsPairingHeapFlatRep], function(h) Print(" Date: Mon, 21 Aug 2017 19:52:12 +0200 Subject: [PATCH 7/7] Update source comment --- gap/plistdeque.gi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gap/plistdeque.gi b/gap/plistdeque.gi index 7821d3d..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.