Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

alt

Daniel Nashed

Lotus Script Tip: Lists with Tag with large lists and keys

Daniel Nashed – 30 September 2018 05:59:34

I have been looking for a fast way to store and lookup values in an array/list to do some statistics counting entries with a certain key.
My first try was to use an array which I redimed once to have a proper size.
Complile time specified limits are not sufficient high for large arrays in my case.

The routine was needed to evaluate data from ma SpamGeek application (SMTP extension manager) used by a customer internally to control their SMTP traffic (allow only defined hosts to send SMTP mails).

It tuned out that using an array was very inefficient from CPU consumption and also run-time.

One of the customers developers came up with the idea using lists with tags. I did not know the List Tags before which turned out to be very effective.
A test routine showed great performance up to at least 500000 entries which is already quite high!

Here are the interesting details of this approach explained with an example. I took the code a wrote for testing and added some additional code an comments for demonstration purposes.

- You first define a List of the data type you need. In my case a long.
- Than you can add your elements with the key your are using.
- To query if an entry already exists there is the Iselement function
- You can only get elements that are in the list. Else you get a run-time error. So you have to test if it is element first!
- You can loop thru the whole list using Forall.
- The Forall variable is your value that your stored in the list
- The Listatag function is used to return the tag that you used

The run-time is really impressive! And the missing part that I did not know about was the "List Tag".

The implementation in the back-end looks highly optimized and there are simple calls to check the list to get elements or to add new elements.

I highlighted the important parts of the code.

Maybe this could help you in one of your next projects.

-- Daniel

        Dim HostList List As Long
        Dim count As Long
        Dim i As Long
        Dim key As String        
       
        '  build a list where the counter is set to the list lable for testing
       
        For i=1 To 100000
                key = Cstr (i)
                HostList (key) = i        
        Next
       
        ' check if key exists in list and get entry and label!
       
        key = "100000"
        If  Iselement(HostList (key)) Then
                count = HostList (key)
                Messagebox "Found Key: " + key + " with value: "+ Cstr (count)
                HostList (key) = count+123
        Else
                Messagebox  "Not found"
        End If
       
       
        ' loop thru list and check if the key is found unsing the Listtag function
       
        Forall h In HostList
                If (key = Listtag(h)) Then
                        Messagebox "Found Key: " + key + " with new value: "+ Cstr (h)
                End If
        End Forall


Links

    Archives


    • [HCL Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]