Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/clean
Original file line number Diff line number Diff line change
@@ -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}

10 changes: 8 additions & 2 deletions gap/binaryheap.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -98,3 +98,9 @@ function(heap)
Print("<binary heap with ", Length(heap![2]), " entries>");
end);

InstallMethod(PostMakeImmutable,
"for a bineary heap",
[ IsBinaryHeapFlatRep ],
function(heap)
MakeImmutable(heap![2]);
end);
12 changes: 10 additions & 2 deletions gap/hashmap.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
4 changes: 1 addition & 3 deletions gap/pairingheap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 12 additions & 5 deletions gap/pairingheap.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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("<pairing heap with "
, h![1]
, " entries>");
end);

InstallMethod(PostMakeImmutable,
"for a pairing heap",
[ IsPairingHeapFlatRep ],
function(h)
MakeImmutable(h![3]);
end);
38 changes: 18 additions & 20 deletions gap/plistdeque.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -293,11 +284,18 @@ function(deque)
return deque![QCAPACITY];
end);

InstallMethod( ViewObj,
"for a PlistDeque",
[ IsPlistDequeRep ],
InstallMethod(ViewObj,
"for IsPlistDeque",
[IsPlistDequeRep],
function(deque)
Print("<deque with ");
Print(Size(deque),"/",Capacity(deque));
Print(" entries>");
end);

InstallMethod(PostMakeImmutable,
"for IsPlistDeque",
[IsPlistDequeRep],
function(deque)
MakeImmutable(deque![QDATA]);
end);
10 changes: 10 additions & 0 deletions gap/queue.gi
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 1 addition & 3 deletions gap/stack.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 9 additions & 3 deletions gap/stack.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand All @@ -55,3 +55,9 @@ function(s)
Print("<stack with ", Length(s![1]), " entries>");
end);

InstallMethod(PostMakeImmutable
, "for a stack"
, [IsStack],
function(s)
MakeImmutable(s![1]);
end);
1 change: 1 addition & 0 deletions read.g
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DeclareInfoClass( "InfoDataStructures" );
SetInfoLevel( InfoDataStructures, 1 );


ReadPackage("datastructures", "gap/queue.gi");
ReadPackage("datastructures", "gap/plistdeque.gi");

ReadPackage("datastructures", "gap/heap.gi");
Expand Down