Link to home
Start Free TrialLog in
Avatar of felonius
felonius

asked on

Does there exist a Standard Library for VB?

In most programming languages there is some support for standard datastructures (Classes) such as lists, queues, trees, b-trees, hash tables, etc. Examples of such support is the STL library for C++. Does such libraries exist for free for VB? Only answer if your know where to get them. It is ok if you made them yourselves so long they are fairly fast & flexible.
Avatar of felonius
felonius

ASKER

Adjusted points to 80
Adjusted points to 100
You could find some librairies on the internet. But the best is creating you own librairy with the functions you could find on Internet.
I suggest you my site :
  http://www.geocities.com/ResearchTriangle/6311/
You will find a lot of useful code.


I have been browsing your links and the only code that gets even close is a "general" stack. First of all, i would prefer if it was written as a class and not as funktions. The second problem is that it is not general. It uses the Variant type as argument, but Variants cannot contain userdefined objects.
I think that it should accept arguments of type Object.

Thanks for the feedback, though. I have used a lot of time on the web looking for these routines and have begun to write them myself now. If nothing comes up soon this question will be deleted.

felonius
What kind of functions do you want? I have classes for stack, linked list...

But I can't release them all (for the moment) they represent 5 years of work and experiences. But I can send you some classes or code if you give me more informations.
Thanks for your response waty,

The classes I think are essential for every programmer is the following:
Single-linked list (functions: next, data, head, insert, delete, clear, copy)
Double-linked list (functions: next, prev, head, tail, insert, delete, clear, copy, data)
Stack (empty, pop, push, top)
Queue (enqueue, dequeue, empty)
Map (find, insert, delete, retrieve, Merge) A map is a associative container in which each element is attached af Key which they are sorted after. By delievering the key, the data can retrieved fast. The usual structure of this container class is that of an AVL-tree.
Hash_Map - a variation of a map in which you also supply a hash function to be able to make speedier retrievals, but at a higher cost of space.
Set (find, subset, union, insert, delete, retrieve, intersection)
A set is a collection of data with no ordering. It is not very unlike the collection concept in VB.

They should be able to contain any type of object. I do not have so much expierience with VB, having written my first VB program only 2 weeks ago. My experience comes primarily from C++. But I think that if you create user-defined objects containing for instance only an Integer, that should be the way to handle Integers as Objects. Maybe some of these classes are impossible to make in VB and so must it be.
If you can supply at least 3 of the above I will accept the answer (the grade depending the quality of the code). If you can give more I will give more points.
If you do not want to give away your code easily I could maybe see one of the classes first and see if I like it. If I do, I can maybe make those classes of the above that you do not have and we could exchange code.

felonius... send to felonius@diku.dk


ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I forgot to add the class_ListItem to use with the linked list

Option Explicit

'  Used with the class_LinkedList class.

Private m_next As class_ListItem
Private m_prev As class_ListItem
Private m_data As Variant

Public Property Set ItemData(v As Variant)
   Set m_data = v
End Property

Public Property Get NextItem() As class_ListItem
   Set NextItem = m_next
End Property

Public Property Set NextItem(ITem As class_ListItem)
   Set m_next = ITem
End Property

Public Property Get PrevItem() As class_ListItem
   Set PrevItem = m_prev
End Property

Public Property Set PrevItem(ITem As class_ListItem)
   Set m_prev = ITem
End Property

Public Property Get ItemData() As Variant
   If (VarType(m_data) = vbObject) Then
      Set ItemData = m_data
   Else
      ItemData = m_data
   End If
End Property

Public Property Let ItemData(v As Variant)
   If (VarType(v) = vbObject) Then
      Set m_data = v
   Else
      m_data = v
   End If
End Property

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 25/09/98
' * Time             : 13:14
' * Module Name      : class_Stack
' * Module Filename  : Stack.cls
' **********************************************************************
' * Comments         : A simple Stack class.
' *
' *
' **********************************************************************

Option Explicit

' Private Data
Private vData As New Collection

Public Sub Clear()
   
   Set vData = New Collection

End Sub

Property Get count() As Long
   '
   ' Returns the number of items in the stack.
   '
   
   count = vData.count

End Property

Public Function Peek() As Variant
   '
   '  Returns the value of the next item on the
   '  stack without removing the item from the
   '  stack.
   '
   
   If vData.count = 0 Then
      Peek = Null
   Else
      If VarType(vData.ITem(1)) = vbObject Then
         Set Peek = vData(1)
      Else
         Peek = vData(1)
      End If
   End If

End Function

Public Function Pop() As Variant
   '
   '  Removes and returns the next item from
   '  the stack.
   '
   
   If vData.count = 0 Then
      Pop = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Set Pop = vData(1)
      Else
         Pop = vData(1)
      End If
      vData.Remove 1
   End If

End Function

Public Sub Push(v As Variant)
   '
   '  Adds an item to the Stack
   '
   
   If vData.count = 0 Then
      vData.Add v
   Else
      vData.Add v, , 1
   End If

End Sub

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 25/09/98
' * Time             : 13:15
' * Module Name      : class_Fifo
' * Module Filename  : FIFO.cls
' **********************************************************************
' * Comments         : A FIFO (First In First Out) buffer.
' *
' *
' **********************************************************************

Option Explicit

Private vData As New Collection

Public Sub Push(v As Variant)
   '
   '  Adds an item to the FIFO
   '
   
   If vData.count = 0 Then
      vData.Add v
   Else
      vData.Add v, , , vData.count
   End If

End Sub

Public Sub Clear()
   '
   '  Clears all items from the FIFO
   '
   
   Set vData = New Collection

End Sub

Public Property Get count() As Integer
   '
   ' Returns the number of items in the FIFO
   '
   
   count = vData.count

End Property

Public Function Pop() As Variant
   '
   '  Returns an item from the FIFO
   '
   
   If vData.count = 0 Then
      Pop = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Set Pop = vData(1)
      Else
         Pop = vData(1)
      End If
      vData.Remove 1
   End If

End Function

Public Function Peek() As Variant
   '
   '  Returns the next item in the FIFO but does
   '  not remove it from the FIFO
   '
   
   If vData.count = 0 Then
      Peek = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Peek = vData(1)
      Else
         Peek = vData(1)
      End If
   End If
End Function

I have added previously some classes that you need (eventually, you could modify them for specific uses). If you enhance them, send them back to me : waty.thierry@usa.net

>Map (find, insert, delete, retrieve, Merge) A map is a >associative container in which each element is attached af Key >which they are sorted after. By delievering the key, the data >can retrieved fast. The usual structure of this container class >is that of an AVL-tree.
It seems as a typical collection in VB excepting the sort.

If you add some more points, I could also give you routines to sort, search, shuffle, compare array, collections. I use them in my Print Preview OCX (see my web site)
The code you have sent is structurally fine. The only problem is that the data they can contain is of type Variant. It was the same problem a saw with the Stack class at your site (as I commented earlier. The stack you posted now is the same as on your site, isn't it?). Is there any way I can insert user defined types into these? Or should I rewrite the classes?

felonius
You can modify the classes to use with UDT instead ov variant.

I don't remember if it is the same class than on my website, but probably.
The grade is based on the fact that I have to rewrite a lot of the code. I is not truely general either. General containers support similar interfaces, so algrorithms can be written for several of them at once.

I will post you a web-site where new version can be found when they are done. I expect it to be at http://www.image.dk/~lisjac/. Currently that site only contains a danish guide to my students at the university, but that will change.

If any code are reused you will be listed in the the "based upon/acknowledgement" section of the code.

I have come to the conclusion that the community does not have a truly general library of code and I thnk that I will make one at distribute it freely. Stay tuned.

felonius