Click here to Skip to main content
15,895,011 members

Roger Keulen - Professional Profile



Summary

    Blog RSS
3
Debator
6
Organiser
606
Participant
0
Author
0
Authority
0
Editor
0
Enquirer
I like syntactic sugar in my coffee

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralMY -> Generic.List(Of T) Math with a generic list in .net [modified] Pin
Roger Keulen13-Jun-11 6:35
Roger Keulen13-Jun-11 6:35 
Example of Use:

Imports Library.Generics

Module LibTest
  Sub Main()
    Dim Lijst1 As New MySortedList(Of Integer)
    Dim Lijst2 As New MySortedList(Of Integer)(1, 2, 3, 4, 5)
    Dim Lijst3 As New MySortedList(Of Integer)(6, 7)

    Lijst1.Add(11, 12, 13, 14, 15)
    Lijst1.Remove(11, 12, 13, 14, 15)


    Lijst1 += {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    EchoLijstjes("Add: ", Lijst1)

    Lijst1 -= {6, 7, 8, 9, 10}
    EchoLijstjes("Remove: ", Lijst1)

    Lijst2 = Lijst1 + {8, 9, 10} + Lijst3
    EchoLijstjes("Add: ", Lijst1, Lijst2, Lijst3)


    Lijst3 = Lijst2 - Lijst1
    EchoLijstjes("Substract: ", Lijst1, Lijst2, Lijst3)

    Lijst1.Init({1, 2, 3}) : Lijst2.Init({1, 2, 3}) : Lijst3.Init({7, 8, 9})
    EchoLijstjes("Init: ", Lijst1, Lijst2, Lijst3)

    
    If Lijst1 = Lijst2 And Lijst1 = {1, 2, 3} Then
      EchoLijstjes("Lijst 1 = Lijst 2: ", Lijst1, Lijst2)
    End If

   
    If Lijst1 <> Lijst3 And Lijst1 <> {0, 4, 5} Then
      EchoLijstjes("Lijst1 <> Lijst2: ", Lijst1, Lijst3)
    End If

    ' Lijst2 += {7, 8, 9}  >> INIT -> ME funtie !!!
    If Lijst2.Init(7, 8, 9) > Lijst3 Then
      EchoLijstjes("Alle Items van lijst2 komen voor in lijst 3: ", Lijst2, Lijst3)
    End If

    Lijst2 += {1, 2, 3, 4, 5}
    If Lijst2 < {1, 2, 3} Then
      EchoLijstjes("Alle Items 1, 2, 3 komen voor in Lijst2: ", Lijst2)
    End If

    If Lijst1 > {1, 2, 3, 4, 5, 6} Then
      EchoLijstjes("Alle Items van lijst1 komen voor in 1, 2, 3, 4, 5, 6: ", Lijst1)
    End If



    Console.ReadKey()
  End Sub

  Public Sub EchoLijstjes(Of T)(ByVal Tekst As String, ByVal ParamArray Lijsten() As MySortedList(Of T))
    Echo(Tekst)
    Dim Counter As Integer = 1
    For Each Lijst As MySortedList(Of T) In Lijsten
      Echo("{0}:{1}", Counter, Lijst.toString())
      Counter += 1
    Next
    Echo(vbNewLine)
  End Sub


  Sub Echo(ByVal Text As String, ByVal ParamArray Args() As Object)
    Console.WriteLine(String.Format(Text, Args))
  End Sub
End Module





Code:

Namespace Generics

  Public Class MySortedList(Of TValue)
    Inherits Generic.SortedList(Of TValue, TValue)

    Public Sub New()
      MyBase.New()
    End Sub
    Public Sub New(ByVal Item As TValue)
      MyBase.New() : AddItem(Item)
    End Sub
    Public Sub New(ByVal ParamArray Items() As TValue)
      MyBase.New() : AddItems(Items)
    End Sub
    Public Sub New(ByVal List As MySortedList(Of TValue))
      MyBase.New() : AddList(List)
    End Sub
    Public Sub New(ByVal Lists() As MySortedList(Of TValue))
      MyBase.New() : AddLists(Lists)
    End Sub

    Protected Sub AddItem(ByVal Item As TValue)
      MyBase.Add(Item, Item)
    End Sub
    Protected Sub AddItems(ByVal Items() As TValue)
      For Each Item As TValue In Items
        MyBase.Add(Item, Item)
      Next
    End Sub
    Protected Sub AddList(ByVal List As MySortedList(Of TValue))
      Dim Array(List.Count - 1) As TValue : List.Values.CopyTo(Array, 0)
      AddItems(Array)
    End Sub
    Protected Sub AddLists(ByVal Lists() As MySortedList(Of TValue))
      For Each List As MySortedList(Of TValue) In Lists
        AddList(List)
      Next
    End Sub

    Protected Sub RemoveItem(ByVal Item As TValue)
      MyBase.Remove(Item)
    End Sub
    Protected Sub RemoveItems(ByVal Items() As TValue)
      For Each Item As TValue In Items
        MyBase.Remove(Item)
      Next
    End Sub
    Protected Sub RemoveList(ByVal List As MySortedList(Of TValue))
      Dim Array(List.Count - 1) As TValue : List.Values.CopyTo(Array, 0)
      RemoveItems(Array)
    End Sub
    Protected Sub RemoveLists(ByVal Lists() As MySortedList(Of TValue))
      For Each List As MySortedList(Of TValue) In Lists
        RemoveList(List)
      Next
    End Sub

    Public Overloads Function Add(ByVal Item As TValue)
      AddItem(Item) : Return Me
    End Function
    Public Overloads Function Add(ByVal ParamArray Items() As TValue)
      AddItems(Items) : Return Me
    End Function
    Public Overloads Function Add(ByVal List As MySortedList(Of TValue))
      AddList(List) : Return Me
    End Function
    Public Overloads Function Add(ByVal Lists() As MySortedList(Of TValue))
      AddLists(Lists) : Return Me
    End Function

    Public Overloads Function Remove(ByVal Item As TValue)
      RemoveItem(Item) : Return Me
    End Function
    Public Overloads Function Remove(ByVal ParamArray Items() As TValue)
      RemoveItems(Items) : Return Me
    End Function
    Public Overloads Function Remove(ByVal List As MySortedList(Of TValue))
      RemoveList(List) : Return Me
    End Function
    Public Overloads Function Remove(ByVal Lists() As MySortedList(Of TValue))
      RemoveLists(Lists) : Return Me
    End Function

    Public Overloads Function Init()
      Clear() : Return Me
    End Function
    Public Overloads Function Init(ByVal Item As TValue)
      Clear() : AddItem(Item) : Return Me
    End Function
    Public Overloads Function Init(ByVal ParamArray Items() As TValue)
      Clear() : AddItems(Items) : Return Me
    End Function
    Public Overloads Function Init(ByVal List As MySortedList(Of TValue))
      Clear() : AddList(List) : Return Me
    End Function
    Public Overloads Function Init(ByVal Lists() As MySortedList(Of TValue))
      Clear() : AddLists(Lists) : Return Me
    End Function

    ' A + B (Alle items van A en B)
    Public Shared Operator +(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Dim NewList As New MySortedList(Of TValue)(ListA) : Return NewList.Add(ItemB)
    End Operator
    Public Shared Operator +(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      Dim NewList As New MySortedList(Of TValue)(ListA) : Return NewList.Add(ItemsB)
    End Operator
    Public Shared Operator +(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      Return New MySortedList(Of TValue)({ListA, ListB})
    End Operator
    Public Shared Operator +(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      Dim NewList = New MySortedList(Of TValue)(ListsB)
      Return NewList.Add(ListA)
    End Operator

    ' A - B (Alle items van A met uitzondering die van B)
    Public Shared Operator -(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Dim NewList As New MySortedList(Of TValue)(ListA) : Return NewList.Remove(ItemB)
    End Operator
    Public Shared Operator -(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      Dim NewList As New MySortedList(Of TValue)(ListA) : Return NewList.Remove(ItemsB)
    End Operator
    Public Shared Operator -(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      Dim NewList As New MySortedList(Of TValue)(ListA) : Return NewList.Remove(ListB)
    End Operator
    Public Shared Operator -(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      Dim NewList = New MySortedList(Of TValue)(ListsB)
      Return NewList.Remove(ListA)
    End Operator

    ' A == B (Alles van A komt voor in B en A is even groot als B)
    Public Shared Operator =(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return ListA.Count = 1 AndAlso ListA.ContainsValue(ItemB)
    End Operator
    Public Shared Operator =(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      If ListA.Count - 1 <> ItemsB.GetUpperBound(0) Then Return False
      Return ContainsAND(ItemsB, ListA, True)
    End Operator
    Public Shared Operator =(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      If ListA.Count <> ListB.Count Then Return False
      Return ContainsAND(ListA, ListB, True)
    End Operator
    Public Shared Operator =(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      Dim Count As Integer = 0
      For Each List As MySortedList(Of TValue) In ListsB
        Count += List.Count
        If ContainsAND(ListA, List, False) Then Return False
      Next
      Return ListA.Count = Count
    End Operator

    ' A <> B (Niks van A komt voor in B)
    Public Shared Operator <>(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return Not ListA.ContainsValue(ItemB)
    End Operator
    Public Shared Operator <>(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      Return ContainsAND(ItemsB, ListA, False)
    End Operator
    Public Shared Operator <>(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      Return ContainsAND(ListA, ListB, False)
    End Operator
    Public Shared Operator <>(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      For Each List As MySortedList(Of TValue) In ListsB
        If ContainsAND(ListA, List, True) Then Return False
      Next
      Return True
    End Operator

    'Alles van A moet voorkomen in B (Haystack)
    Public Shared Operator >=(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return ListA.ContainsKey(ItemB)
    End Operator
    Public Shared Operator >=(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      Return ContainsAND(ListA, ItemsB, True)
    End Operator
    Public Shared Operator >=(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      Return ContainsAND(ListA, ListB, True)
    End Operator
    Public Shared Operator >=(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      For Each ItemA As Generic.KeyValuePair(Of TValue, TValue) In ListA

        Dim ContainsA As Boolean = False
        For Each ListB As MySortedList(Of TValue) In ListsB
          ContainsA = ContainsAND(ItemA.Value, ListB, True)
          If ContainsA Then Exit For
        Next ListB

        If Not ContainsA Then Return False
      Next ItemA
      Return True
    End Operator

    'Alles van B moet voorkomen in A (Haystack)
    Public Shared Operator <=(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return ListA.ContainsKey(ItemB)
    End Operator
    Public Shared Operator <=(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      Return ContainsAND(ItemsB, ListA, True)
    End Operator
    Public Shared Operator <=(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      Return ContainsAND(ListB, ListA, True)
    End Operator
    Public Shared Operator <=(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      For Each List As MySortedList(Of TValue) In ListsB
        If ContainsAND(List, ListA, True) Then Return False
      Next
      Return True
    End Operator

    'Eentje van A moet voorkomen in B (Haystack)
    Public Shared Operator >(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return ListA.ContainsKey(ItemB)
    End Operator
    Public Shared Operator >(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      For Each Item As TValue In ItemsB  ' // Verkeerd om !
        If ListA.ContainsKey(Item) Then Return True
      Next
      Return False
    End Operator
    Public Shared Operator >(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      For Each Item As TValue In ListA.Values
        If ListB.ContainsKey(Item) Then Return True
      Next
      Return False
    End Operator
    Public Shared Operator >(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      For Each ItemA As Generic.KeyValuePair(Of TValue, TValue) In ListA
        For Each ListB As MySortedList(Of TValue) In ListsB
          If ContainsAND(ItemA.Value, ListB, True) Then Return True
        Next ListB
      Next ItemA
      Return False
    End Operator

    'Eentje van B moet voorkomen in A (Haystack)
    Public Shared Operator <(ByVal ListA As MySortedList(Of TValue), ByVal ItemB As TValue)
      Return ListA.ContainsKey(ItemB)
    End Operator
    Public Shared Operator <(ByVal ListA As MySortedList(Of TValue), ByVal ItemsB() As TValue)
      For Each Value As TValue In ItemsB
        If ListA.ContainsKey(Value) Then Return True
      Next
      Return False
    End Operator
    Public Shared Operator <(ByVal ListA As MySortedList(Of TValue), ByVal ListB As MySortedList(Of TValue))
      For Each Item As TValue In ListB.Values
        If ListA.ContainsKey(Item) Then Return True
      Next
      Return False
    End Operator
    Public Shared Operator <(ByVal ListA As MySortedList(Of TValue), ByVal ListsB() As MySortedList(Of TValue))
      For Each ItemA As Generic.KeyValuePair(Of TValue, TValue) In ListA  ' Ook verkeerd om !
        For Each ListB As MySortedList(Of TValue) In ListsB
          If ContainsAND(ItemA.Value, ListB, True) Then Return True
        Next ListB
      Next ItemA
      Return False
    End Operator


    Private Shared Function ContainsAND(ByVal Needle As TValue, ByVal Haystack As MySortedList(Of TValue), Optional ByVal _Not As Boolean = True) As Boolean
      Return (Not _Not) Xor Haystack.ContainsValue(Needle)
    End Function
    Private Shared Function ContainsAND(ByVal Needle() As TValue, ByVal Haystack As MySortedList(Of TValue), Optional ByVal _Not As Boolean = True) As Boolean
      For Each Value As TValue In Needle
        If Not ContainsAND(Value, Haystack, _Not) Then Return False
      Next : Return True
    End Function
    Private Shared Function ContainsAND(ByVal Needle As MySortedList(Of TValue), ByVal Haystack As MySortedList(Of TValue), Optional ByVal _Not As Boolean = True) As Boolean
      For Each Value As TValue In Needle.Values
        If Not ContainsAND(Value, Haystack, _Not) Then Return False
      Next : Return True
    End Function
    Private Shared Function ContainsAND(ByVal Needle As MySortedList(Of TValue), ByVal Haystacks() As TValue, Optional ByVal _Not As Boolean = True) As Boolean
      Dim C As Integer = 0
      For Each Haystack As TValue In Haystacks
        If ContainsAND(Haystack, Needle, _Not) Then C += 1
      Next : Return C = Needle.Count
    End Function


    Public Shadows Function toString() As String
      Dim Result As String = ""
      For Each Item As TValue In Values
        If Result <> "" Then Result += ", "
        Result += Item.ToString
      Next
      Return Result
    End Function
  End Class
End Namespace


modified on Tuesday, June 14, 2011 2:52 PM

GeneralPHP Simple List object [modified] Pin
Roger Keulen13-Jun-11 6:25
Roger Keulen13-Jun-11 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.