Skip to content

Commit

Permalink
add set
Browse files Browse the repository at this point in the history
  • Loading branch information
tci12 committed Apr 7, 2012
1 parent f764722 commit 42c28db
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions lib/set.vbs
@@ -0,0 +1,108 @@
Class TSet
Dim left
Dim right
Dim parent
Dim value
Dim i

Property Let parentNode(p)
Set parent = p
End Property

Property Get leftNode()
leftNode = left
End Property

Property Get rightNode()
rightNode = right
End Property

Property Get getValue()
getValue = value
End Property

Sub init
i = False
End Sub

Sub insert(ByVal p)

If Not Me.i Then
value = p
i = True
Set left = Nothing
Set right = Nothing
Exit Sub
End If

If p = value Then
Exit Sub
End If

If p > value Then
If right is Nothing Then
Set right = new TSet
right.init
right.parentNode = Me
End If
right.insert(p)
Else
If left is Nothing Then
Set left = new TSet
left.init
left.parentNode = Me
End If
left.insert(p)
End If

End Sub

Sub clearAll()
Me.i = False
Set value = Nothing
Set left = Nothing
Set right = Nothing
End Sub


Function getValues()
If Me.i Then
Dim leftA,rightA
Dim size
size = 0

If Not Me.left is Nothing Then
leftA = left.getValues
size = size + (UBound(leftA)+1)
End If
If Not Me.right is Nothing Then
rightA = right.getValues
size = size + (UBound(rightA)+1)
End If
MsgBox size
Redim tmp(size)
Dim x
Dim ip
i = 0
If Not Me.left is Nothing Then
ip = x
For x = ip to ip+Ubound(leftA)
tmp(x) = leftA(x-ip)
Next
End If
tmp(x) = value
x = x+1
If Not Me.right is Nothing Then
ip = x
For x = ip to ip+Ubound(RightA)
tmp(x) = rightA(x-ip)
Next
End If
getValues = tmp
Else
Set getValues = Nothing
End If

End Function

End Class

0 comments on commit 42c28db

Please sign in to comment.