## ## Datastructures: GAP package providing common datastructures. ## ## Copyright (C) 2015-2017 The datastructures team. ## For list of the team members, please refer to the COPYRIGHT file. ## ## This package is licensed under the GPL 2 or later, please refer ## to the COPYRIGHT.md and LICENSE files for details. ##
## ## Doubly linked lists. ##
## ## Why doubly linked lists, and not just GAP plain lists: ## Doubly linked lists have better add/remove behaviour than lists ## If things are removed in the middle of a list, you either end up ## with an unbound entry or have to copy entries, both potentially ## expensive operations. ## ## Doubly Linked Lists SHOULD have the following complexity guarantees ## PushFront: O(1) ## PushBack: O(1) ## Add: O(n) (O(1) if given a node in the list) ## PopFront: O(1) ## PopBack: O(1) ## Remove: O(n) (O(1) if given a node in the list) ##
InstallGlobalFunction(NewDoublyLinkedListNode, function()
local r;
r := rec( prev := fail, next := fail, obj := fail );
return Objectify(DoublyLinkedListNodeType, r); end);
InstallGlobalFunction(NewDoublyLinkedList, function()
local l, t;
l := rec( entry := NewDoublyLinkedListNode(), nrobs := 0 );
t := NewType(DoublyLinkedListFamily, IsDoublyLinkedListRep and IsMutable);
InstallMethod(ViewObj, "for doubly linked lists",
true,
[IsDoublyLinkedList and IsDoublyLinkedListRep], function( dll )
Print("<doubly linked list with ", dll!.nrobs, " nodes>"); end );
InstallMethod(InsertBefore, "for a doubly linked list, a node, and an object",
true,
[ IsDoublyLinkedListRep, IsDoublyLinkedListNode, IsObject ], function(dll, nd, obj)
local newnd;
InstallMethod(InsertAfter, "for a doubly linked list, a node, and an object",
true,
[ IsDoublyLinkedListRep, IsDoublyLinkedListNode, IsObject ], function(dll, nd, obj)
local newnd;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.