diff --git a/docs/AllClasses.html b/docs/AllClasses.html
index cbc5ec9..e3d719d 100644
--- a/docs/AllClasses.html
+++ b/docs/AllClasses.html
@@ -18,6 +18,11 @@
All Classes, Interfaces, Objects and Records
Description |
+TImplicitTreapNode |
+ftreap |
+ |
+
+
TTreapNode |
ftreap |
|
diff --git a/docs/AllIdentifiers.html b/docs/AllIdentifiers.html
index bca402e..e70db49 100644
--- a/docs/AllIdentifiers.html
+++ b/docs/AllIdentifiers.html
@@ -18,6 +18,11 @@ All Identifiers
Description |
+TImplicitTreapNode |
+ftreap |
+ |
+
+
TTreapNode |
ftreap |
|
diff --git a/docs/ClassHierarchy.html b/docs/ClassHierarchy.html
index 3bcc840..24dc83b 100644
--- a/docs/ClassHierarchy.html
+++ b/docs/ClassHierarchy.html
@@ -13,7 +13,7 @@
Class Hierarchy
Generated by PasDoc 0.15.0.
diff --git a/docs/ftreap.TImplicitTreapNode.html b/docs/ftreap.TImplicitTreapNode.html
new file mode 100644
index 0000000..fca6ab3
--- /dev/null
+++ b/docs/ftreap.TImplicitTreapNode.html
@@ -0,0 +1,277 @@
+
+
+
+ftreap: Class TImplicitTreapNode
+
+
+
+
+
+
+
+ Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
+Class TImplicitTreapNode
+
+Unit
+
+ftreap
+Declaration
+
+type generic TImplicitTreapNode<T> = class(TObject)
+Description
+Hierarchy
+- TObject
+- TImplicitTreapNode
Overview
+Fields
+
+Methods
+
+Description
+Fields
+
+
+ |
+FValue: T; |
+
+
+
+Value
+ |
+
+
+
+ |
+FPriority: extended; |
+
+
+
+Random heap priority
+ |
+
+
+
+ |
+FSize: SizeUInt; |
+
+
+
+Number of nodes in subtree
+ |
+
+
+
+Methods
+
+
+ |
+constructor Create(const v: T); |
+
+
+
+Tree node constructor.
+ |
+
+
+
+ |
+destructor Destroy; override; |
+
+
+
+Tree node destructor.
+ |
+
+
+
+ |
+class function GetSize(const node: TImplicitTreapNode): SizeUInt; inline; |
+
+
+
+Returns number of keys in the tree rooted at node .
+ |
+
+
+
+ |
+class procedure UpdateSize(const node: TImplicitTreapNode); inline; |
+
+
+
+Recalculates number of nodes in the tree rooted at node after insert, delete operations.
+ |
+
+
+
+
+
+ |
+class function IsEmpty(const node: TImplicitTreapNode): boolean; inline; |
+
+
+
+Returns True if tree rooted at node is empty, False otherwise
+ |
+
+
+
+ |
+class procedure InsertAt(var node: TImplicitTreapNode; const pos: SizeUInt; const v: T); inline; |
+
+
+
+Insert value k at position in tree rooted at node .
+ |
+
+
+
+ |
+class function GetAt(node: TImplicitTreapNode; pos: SizeUInt): T; |
+
+
+ Exceptions raised
+
+EArgumentException
+
+
+ |
+
+
+
+ |
+class function RemoveAt(var node: TImplicitTreapNode; const pos: SizeUInt): T; |
+
+
+
+Removes value from the given position.
+Returns
+key |
+
+
+
+ Generated by PasDoc 0.15.0.
+
+ |
diff --git a/docs/ftreap.TTreapNode.html b/docs/ftreap.TTreapNode.html
index 58434dc..32f3480 100644
--- a/docs/ftreap.TTreapNode.html
+++ b/docs/ftreap.TTreapNode.html
@@ -70,54 +70,66 @@ Description
 |
-class procedure Divide(node: TTreapNode; k: T; var l, r: TTreapNode); |
+class procedure DivideRight(node: TTreapNode; k: T; var l, r: TTreapNode); |
 |
-class procedure DivideAt(node: TTreapNode; const pos: SizeUInt; var l, r: TTreapNode); |
+class procedure DivideLeft(node: TTreapNode; k: T; var l, r: TTreapNode); |
 |
-class function IsEmpty(const node: TTreapNode): boolean; inline; |
+class procedure DivideAt(node: TTreapNode; const pos: SizeUInt; var l, r: TTreapNode); |
 |
-class procedure Insert(var node: TTreapNode; const k: T); inline; |
+class function IsEmpty(const node: TTreapNode): boolean; inline; |
 |
-class function Contains(node: TTreapNode; const k: T): boolean; inline; |
+class procedure Insert(var node: TTreapNode; const k: T); inline; |
 |
-class function BisectLeft(node: TTreapNode; const k: T): SizeUInt; |
+class function Contains(node: TTreapNode; const k: T): boolean; inline; |
 |
-class function BisectRight(node: TTreapNode; const k: T): SizeUInt; |
+class function BisectLeft(node: TTreapNode; const k: T): SizeUInt; |
 |
-class function GetPosition(node: TTreapNode; const k: T): SizeUInt; |
+class function BisectRight(node: TTreapNode; const k: T): SizeUInt; |
 |
+class function GetPosition(node: TTreapNode; const k: T): SizeUInt; |
+
+
+ |
class function GetAt(node: TTreapNode; pos: SizeUInt): T; |
+
+ |
+class function Min(node: TTreapNode): T; |
+
 |
-class function Remove(var node: TTreapNode; const k: T): boolean; |
+class function Max(node: TTreapNode): T; |
 |
-class function RemoveAt(var node: TTreapNode; const pos: SizeUInt): T; |
+class function Remove(var node: TTreapNode; const k: T): boolean; |
 |
-class procedure DestroyTreap(var node: TTreapNode); |
+class function RemoveAt(var node: TTreapNode; const pos: SizeUInt): T; |
 |
+class procedure DestroyTreap(var node: TTreapNode); |
+
+
+ |
class function CheckStucture(node: TTreapNode): boolean; |
@@ -227,7 +239,7 @@ Methods
 |
-class procedure Divide(node: TTreapNode; k: T; var l, r: TTreapNode); |
+class procedure DivideRight(node: TTreapNode; k: T; var l, r: TTreapNode); |
@@ -237,11 +249,21 @@ Methods
 |
+class procedure DivideLeft(node: TTreapNode; k: T; var l, r: TTreapNode); |
+
+
+
+Divides tree into two trees. Where Max(l) < k .
+ |
+
+
+
+ |
class procedure DivideAt(node: TTreapNode; const pos: SizeUInt; var l, r: TTreapNode); |
-Divides tree into two trees. Where Size(l) = pos + 1 .
+Divides tree into two trees. Where Size(l) = pos .
|
@@ -318,6 +340,22 @@ Methods
+
+
+ |
+class function Max(node: TTreapNode): T; |
+
+
+ |
+
+
+
+ |
class function Remove(var node: TTreapNode; const k: T): boolean; |
diff --git a/docs/ftreap.html b/docs/ftreap.html
index 5a7974f..05ce6c8 100644
--- a/docs/ftreap.html
+++ b/docs/ftreap.html
@@ -25,6 +25,10 @@ Unit ftreap
| Class TTreapNode |
|
+
+Class TImplicitTreapNode |
+ |
+
Generated by PasDoc 0.15.0.
diff --git a/ftreap.pas b/ftreap.pas
index 1adf501..7d8f6e3 100644
--- a/ftreap.pas
+++ b/ftreap.pas
@@ -67,6 +67,8 @@ generic TTreapNode = class
(* @raises(EArgumentException) *)
class function GetAt(node: TTreapNode; pos: SizeUInt): T;
+ class function Min(node: TTreapNode): T;
+ class function Max(node: TTreapNode): T;
(* Removes key from the tree.
@returns(@true if successful, @false otherwise) *)
@@ -360,6 +362,26 @@ class function TTreapNode.GetAt(node: TTreapNode; pos: SizeUInt): T;
raise Exception.Create('Unreachable point.');
end;
+// Min, Max
+class function TTreapNode.Min(node: TTreapNode): T;
+begin
+ if node = nil then
+ raise EArgumentException.Create('Set is empty.');
+ while node.FLeft <> nil do
+ node := node.FLeft;
+ Exit(node.FKey);
+end;
+
+class function TTreapNode.Max(node: TTreapNode): T;
+begin
+ if node = nil then
+ raise EArgumentException.Create('Set is empty.');
+ while node.FRight <> nil do
+ node := node.FRight;
+ Exit(node.FKey);
+end;
+// Min, Max
+
class function TTreapNode.Remove(var node: TTreapNode; const k: T): boolean;
var
n: TTreapNode;
diff --git a/test/treaptestcase.pas b/test/treaptestcase.pas
index be3cc28..97041c0 100644
--- a/test/treaptestcase.pas
+++ b/test/treaptestcase.pas
@@ -162,7 +162,7 @@ procedure TTreapTestCase.TestMin;
try
begin
for i := 0 to KEYS_NUMBER - 1 do
- AssertEquals(0, TIntTreapNode.GetAt(root, 0));
+ AssertEquals(0, TIntTreapNode.Min(root));
end;
except
Fail('Invalid min key!');
@@ -179,7 +179,7 @@ procedure TTreapTestCase.TestMax;
s := TIntTreapNode.GetSize(root);
for i := 0 to KEYS_NUMBER - 1 do
begin
- AssertEquals(2 * (KEYS_NUMBER - 1), TIntTreapNode.GetAt(root, s-1));
+ AssertEquals(2 * (KEYS_NUMBER - 1), TIntTreapNode.Max(root));
end;
end;
except
|