|
@@ -6,12 +6,14 @@ bbdoc: Data structures/Linked lists
|
|
End Rem
|
|
End Rem
|
|
Module BRL.LinkedList
|
|
Module BRL.LinkedList
|
|
|
|
|
|
-ModuleInfo "Version: 1.10"
|
|
|
|
|
|
+ModuleInfo "Version: 1.11"
|
|
ModuleInfo "Author: Mark Sibly"
|
|
ModuleInfo "Author: Mark Sibly"
|
|
ModuleInfo "License: zlib/libpng"
|
|
ModuleInfo "License: zlib/libpng"
|
|
ModuleInfo "Copyright: Blitz Research Ltd"
|
|
ModuleInfo "Copyright: Blitz Research Ltd"
|
|
ModuleInfo "Modserver: BRL"
|
|
ModuleInfo "Modserver: BRL"
|
|
|
|
|
|
|
|
+ModuleInfo "History: 1.11"
|
|
|
|
+ModuleInfo "History: Fixed Delete issues with revised GC finalizer."
|
|
ModuleInfo "History: 1.10"
|
|
ModuleInfo "History: 1.10"
|
|
ModuleInfo "History: Fixed TLink removal during iteration issue."
|
|
ModuleInfo "History: Fixed TLink removal during iteration issue."
|
|
ModuleInfo "History: 1.09"
|
|
ModuleInfo "History: 1.09"
|
|
@@ -27,10 +29,6 @@ ModuleInfo "History: Added optional CompareFunc parameter to Sort"
|
|
ModuleInfo "History: 1.05 Release"
|
|
ModuleInfo "History: 1.05 Release"
|
|
ModuleInfo "History: Sort now swaps links instead of values"
|
|
ModuleInfo "History: Sort now swaps links instead of values"
|
|
|
|
|
|
-?Threaded
|
|
|
|
-Import BRL.Threads
|
|
|
|
-?
|
|
|
|
-
|
|
|
|
Function CompareObjects( o1:Object,o2:Object )
|
|
Function CompareObjects( o1:Object,o2:Object )
|
|
Return o1.Compare( o2 )
|
|
Return o1.Compare( o2 )
|
|
End Function
|
|
End Function
|
|
@@ -42,7 +40,6 @@ Type TLink
|
|
|
|
|
|
Field _value:Object
|
|
Field _value:Object
|
|
Field _succ:TLink,_pred:TLink
|
|
Field _succ:TLink,_pred:TLink
|
|
- Field _removed:Int
|
|
|
|
|
|
|
|
Rem
|
|
Rem
|
|
bbdoc: Returns the Object associated with this Link.
|
|
bbdoc: Returns the Object associated with this Link.
|
|
@@ -72,9 +69,6 @@ Type TLink
|
|
_value=Null
|
|
_value=Null
|
|
_succ._pred=_pred
|
|
_succ._pred=_pred
|
|
_pred._succ=_succ
|
|
_pred._succ=_succ
|
|
- _removed = True
|
|
|
|
- _pred=Null
|
|
|
|
- _succ=Null
|
|
|
|
End Method
|
|
End Method
|
|
|
|
|
|
End Type
|
|
End Type
|
|
@@ -84,29 +78,10 @@ bbdoc: Enumerator Object use by TList in order to implement Eachin support.
|
|
End Rem
|
|
End Rem
|
|
Type TListEnum
|
|
Type TListEnum
|
|
|
|
|
|
- Global _pool:TList = New TList
|
|
|
|
-?Threaded
|
|
|
|
- Global _mutex:TMutex = CreateMutex()
|
|
|
|
-?
|
|
|
|
-
|
|
|
|
Field _link:TLink
|
|
Field _link:TLink
|
|
- Field _list:TList
|
|
|
|
|
|
|
|
Method HasNext()
|
|
Method HasNext()
|
|
- Local has:Int = _link._value<>_link And Not _link._removed
|
|
|
|
- If Not has Then
|
|
|
|
-?Threaded
|
|
|
|
- LockMutex(_mutex)
|
|
|
|
-?
|
|
|
|
- _pool.AddLast(Self)
|
|
|
|
-
|
|
|
|
- _link = Null
|
|
|
|
- _list = Null
|
|
|
|
-?Threaded
|
|
|
|
- UnlockMutex(_mutex)
|
|
|
|
-?
|
|
|
|
- End If
|
|
|
|
- Return has
|
|
|
|
|
|
+ Return _link._value<>_link
|
|
End Method
|
|
End Method
|
|
|
|
|
|
Method NextObject:Object()
|
|
Method NextObject:Object()
|
|
@@ -139,10 +114,10 @@ Type TList
|
|
|
|
|
|
'?Not Threaded
|
|
'?Not Threaded
|
|
Method Delete()
|
|
Method Delete()
|
|
- Clear
|
|
|
|
- _head._value=Null
|
|
|
|
- _head._succ=Null
|
|
|
|
- _head._pred=Null
|
|
|
|
|
|
+' Clear
|
|
|
|
+' _head._value=Null
|
|
|
|
+' _head._succ=Null
|
|
|
|
+' _head._pred=Null
|
|
End Method
|
|
End Method
|
|
'?
|
|
'?
|
|
Rem
|
|
Rem
|
|
@@ -408,7 +383,6 @@ Type TList
|
|
Method Sort( ascending=True,compareFunc( o1:Object,o2:Object )=CompareObjects )
|
|
Method Sort( ascending=True,compareFunc( o1:Object,o2:Object )=CompareObjects )
|
|
Local ccsgn=-1
|
|
Local ccsgn=-1
|
|
If ascending ccsgn=1
|
|
If ascending ccsgn=1
|
|
- Local modded:Int
|
|
|
|
|
|
|
|
Local insize=1
|
|
Local insize=1
|
|
Repeat
|
|
Repeat
|
|
@@ -452,7 +426,6 @@ Type TList
|
|
t._pred=tail
|
|
t._pred=tail
|
|
tail._succ=t
|
|
tail._succ=t
|
|
tail=t
|
|
tail=t
|
|
- modded = True
|
|
|
|
Forever
|
|
Forever
|
|
p=q
|
|
p=q
|
|
Wend
|
|
Wend
|
|
@@ -469,18 +442,8 @@ Type TList
|
|
End Method
|
|
End Method
|
|
|
|
|
|
Method ObjectEnumerator:TListEnum()
|
|
Method ObjectEnumerator:TListEnum()
|
|
-?Threaded
|
|
|
|
- LockMutex(TListEnum._mutex)
|
|
|
|
-?
|
|
|
|
- Local enumeration:TListEnum=TListEnum(TListEnum._pool.RemoveFirst())
|
|
|
|
-?Threaded
|
|
|
|
- UnlockMutex(TListEnum._mutex)
|
|
|
|
-?
|
|
|
|
- If Not enumeration Then
|
|
|
|
- enumeration = New TListEnum
|
|
|
|
- End If
|
|
|
|
|
|
+ Local enumeration:TListEnum=New TListEnum
|
|
enumeration._link=_head._succ
|
|
enumeration._link=_head._succ
|
|
- enumeration._list = Self
|
|
|
|
Return enumeration
|
|
Return enumeration
|
|
End Method
|
|
End Method
|
|
|
|
|
|
@@ -511,12 +474,22 @@ Type TList
|
|
Return list
|
|
Return list
|
|
End Function
|
|
End Function
|
|
|
|
|
|
|
|
+ Rem
|
|
|
|
+ bbdoc: Remove an object from a linked list.
|
|
|
|
+ End Rem
|
|
|
|
+ Method RemoveLink( link:TLink )
|
|
|
|
+ If _count > -1 Then
|
|
|
|
+ _count :- 1
|
|
|
|
+ End If
|
|
|
|
+ link.Remove
|
|
|
|
+ End Method
|
|
|
|
+
|
|
End Type
|
|
End Type
|
|
|
|
|
|
Rem
|
|
Rem
|
|
bbdoc: Create a linked list
|
|
bbdoc: Create a linked list
|
|
returns: A new linked list object
|
|
returns: A new linked list object
|
|
-end rem
|
|
|
|
|
|
+End Rem
|
|
Function CreateList:TList()
|
|
Function CreateList:TList()
|
|
Return New TList
|
|
Return New TList
|
|
End Function
|
|
End Function
|
|
@@ -617,15 +590,7 @@ End Function
|
|
Rem
|
|
Rem
|
|
bbdoc: Remove an object from a linked list
|
|
bbdoc: Remove an object from a linked list
|
|
about: #ListRemove scans a list for the specified value and removes its link.
|
|
about: #ListRemove scans a list for the specified value and removes its link.
|
|
-end rem
|
|
|
|
|
|
+End Rem
|
|
Function ListRemove( list:TList,value:Object )
|
|
Function ListRemove( list:TList,value:Object )
|
|
list.Remove value
|
|
list.Remove value
|
|
End Function
|
|
End Function
|
|
-
|
|
|
|
-Rem
|
|
|
|
-bbdoc: Remove an object from a linked list
|
|
|
|
-about: #RemoveLink is more efficient than #ListRemove.
|
|
|
|
-end rem
|
|
|
|
-Function RemoveLink( link:TLink )
|
|
|
|
- link.Remove
|
|
|
|
-End Function
|
|
|