Author(s): David Trallero Mena.
Version: 1.10#7 (2006/4/26, 19:22:13 CEST)
Version of last change: 1.9#116 (2003/12/1, 22:4:57 CET)
This library allows the user to work with double linked lists. An index is used for referencing the current element in the list. Such index can be modified by next and prev predicated. The value of the current index can be obtained with top predicate
ddlist
):- use_module(library(ddlist)).
ddlist
)
Usage: null_list(?NullList)
NullList
is an empty list
A
is a free variable.
(term_typing:var/1
)
A
is double linked list
(ddlist:ddlist/1
)
Usage: next(OldList, NewList)
NewList
is OldList
but index is set to next element of current element of OldList. It satisfies next(A,B),prev(B,A)
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: prev(OldList, NewList)
NewList
is OldList
but index is set to previous element of current element of OldList
op) of OldList
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: insert(List, Element, NewList)
NewList
is like List
but with Element
inserted _BEFORE_ the current index It satisfies insert( X , A , Xp ) , delete( Xp , X ).
List
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: insert_top(List, Element, NewList)
Element
as new top of NewList
and push the rest of elements after it. It satisfies top( NewList , element )
List
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: insert_after(List, Element, NewList)
NewList
is like List
but with Element
inserted _AFTER_ the current index It satisfies insert_after( X , A , Xp ) , delete_after( Xp , X ).
List
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: delete(OldList, NewList)
NewList
does not have the previous element (top(prev)) of OldList
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: delete_top(OldList, NewList)
NewList
does not have the current element (top) of OldList
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: delete_after(OldList, NewList)
NewList
does not have next element to current element (top) of OldList
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: top(List, Element)
Element
is the element pointed by index
List
is double linked list
(ddlist:ddlist/1
)
Usage: rewind(OldList, NewList)
NewList
is the OldList
but index is set to 0
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: forward(OldList, NewList)
NewList
is the OldList
but index is set to lentgh of NewList
OldList
is double linked list
(ddlist:ddlist/1
)
NewList
is double linked list
(ddlist:ddlist/1
)
Usage: length(List, Len)
Len
is the length of the List
List
is double linked list
(ddlist:ddlist/1
)
Usage: length_next(List, Len)
Len
is the length from the current index till the end
List
is double linked list
(ddlist:ddlist/1
)
Usage: length_prev(List, Len)
Len
is the length from the beginning till the current index
List
is double linked list
(ddlist:ddlist/1
)
Usage: ddlist(X)
X
is double linked list
ddlist
)
Two simple examples of the use of the ddlist library package follow.
:- module( ddl1 , _ , [] ). :- use_module( library(ddlist) ). main(A,B):- % L = [] null_list( L ), % L = [1] insert_after( L , 1 , L1 ), % L = [1,2] insert_after( L1 , 2 , L2 ), % L = [1,3,2] insert_after( L2 , 3 , L3 ), % L = [1,3,2] => A = [1] top( L3 , A ), % L = [3,2] next( L3 , PL3 ), % L = [3,2] => A = [3] top( PL3 , B ).
:- module( ddl2 , _ , [] ). :- use_module( library(ddlist) ). main(A,B):- % L = [] null_list( L ), % L = [1] insert_after( L , 1 , L1 ), % L = [1,2] insert_after( L1 , 2 , L2 ), % L = [1,2] insert( L2 , 3 , L3 ), % L = [3,1,2] prev( L3 , PL3 ), % L = [], forward( PL3 , FOR ), % L = [2] prev( FOR , FOR1 ), % L = [2] => A = 2 top( FOR1 , A ), % L = [1,2] prev( FOR1 , FOR2 ), % L = [2] delete_after( FOR2 , FOR3 ), % L = [3,2] prev( FOR3, FOR4 ), % L = [3,2] => B = 3 top( FOR4 , B ).
Go to the first, previous, next, last section, table of contents.