needs Error.inc and GlobalMem.inc to compile (in download)
Code:
'PB 9 %ErrHaltActive = 1 $TestSource = "LongListC.bas" $TestTitle = "LongListC" #Compile Exe "LongListC.exe" #Dim All #Optimize Speed #Include Once "PBForms.INC" #Include "LongListC.inc" ' %Dlg1 = 101 %BtnTest = 1002 %Lbx = 1001 ' Sub BtnTest(ByVal hDlg As Long) Register i As Long Register Count As Long Local node As Long Register d As Ext Local e As ErrT Local list As LongListI : list = Class "LongListC" : list.Initialize(e) ' ListBox Reset hDlg, %Lbx ' ' this is a hybrid PB COM object ' internal memory must be allocated before use list.Alloc() ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "get internal memory handle: " + Format$(list.Ptr) ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "add 5 items" For i = 1 To 5 list.Add(i) Next i ListBox Add hDlg, %Lbx, "traverse forward" node = list.First() While node ListBox Add hDlg, %Lbx, Str$(list.GetValueAt(node)) node = list.Next(node) Wend ListBox Add hDlg, %Lbx, "traverse backward" node = list.Last() While node ListBox Add hDlg, %Lbx, Str$(list.GetValueAt(node)) node = list.Previous(node) Wend ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "got to first item" node = list.First() ListBox Add hDlg, %Lbx, " insert 0 before" list.InsertBefore(node, 0) ListBox Add hDlg, %Lbx, " insert 11 after" list.InsertAfter(node, 11) ' ListBox Add hDlg, %Lbx, "got to last item" node = list.Last() ListBox Add hDlg, %Lbx, " insert 44 before" list.InsertBefore(node, 44) ListBox Add hDlg, %Lbx, " insert 55 after" list.InsertAfter(node, 55) ' ListBox Add hDlg, %Lbx, "traverse list" node = list.First() While node ListBox Add hDlg, %Lbx, Str$(list.GetValueAt(node)) node = list.next(node) Wend ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "move to second item in list: = 1" node = list.First() : node = list.Next(node) ListBox Add hDlg, %Lbx, " delete item before" list.RemovePrevoius(node) ListBox Add hDlg, %Lbx, " delete item after" list.RemoveNext(node) ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "move to second from end of list: = 5" node = list.Last() : node = list.Previous(node) ListBox Add hDlg, %Lbx, " delete item before" list.RemovePrevoius(node) ListBox Add hDlg, %Lbx, " delete item after" list.RemoveNext(node) ' ListBox Add hDlg, %Lbx, "traverse list" node = list.First() While node ListBox Add hDlg, %Lbx, Str$(list.GetValueAt(node)) node = list.Next(node) Wend ' ' Count = 100000 ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "Speed Test" ListBox Add hDlg, %Lbx, " clear list" list.Clear() ListBox Add hDlg, %Lbx, " add "+Format$(Count, "#,.")+" items to list" d = Timer For i = Count To 1 Step - 1 list.Add(i) Next i ListBox Add hDlg, %Lbx, " Time = " + Format$(Timer - d, "0000000000.0000000000") ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, " traverse all "+Format$(Count, "#,.")+" items" d = Timer node = list.First() While node ''''''''listbox add hDlg, %Lbx, format$(list.GetValueAt(node)) node = list.Next(node) Wend ListBox Add hDlg, %Lbx, " Time = " + Format$(Timer - d, "0000000000.0000000000") ' ' internal memory must be freed before object goes out of scope list.Free() list = Nothing 'not necessary ' ListBox Add hDlg, %Lbx, "" ListBox Add hDlg, %Lbx, "done..." End Sub ' Function PBMain() ShowDlg1 %HWND_Desktop End Function CallBack Function ShowDlg1Proc() Select Case As Long CbMsg Case %WM_Command Select Case As Long CbCtl Case %BtnTest If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then BtnTest(Cb.Hndl) End If End Select End Select End Function Function ShowDlg1(ByVal hParent As Dword) As Long Local lRslt As Long Local hDlg As Dword Local hFont1 As Dword Dialog New hParent, $TestTitle, 67, 61, 341, 241, %WS_Popup _ Or %WS_Border Or %WS_DlgFrame Or %WS_Caption Or %WS_SysMenu Or _ %WS_MinimizeBox Or %WS_ClipSiblings Or %WS_Visible Or %DS_ModalFrame _ Or %DS_3DLook Or %DS_NoFailCreate Or %DS_SetFont, _ %WS_Ex_ControlParent Or %WS_Ex_Left Or %WS_Ex_LtrReading Or _ %WS_Ex_RightScrollbar, To hDlg Control Add ListBox, hDlg, %Lbx, , 5, 5, 330, 210, %WS_Child Or _ %WS_Visible Or %WS_HScroll Or %WS_VScroll Or %LBS_Notify Or _ %LBS_NoIntegralHeight, %WS_Ex_ClientEdge Or %WS_Ex_Left Or _ %WS_Ex_LtrReading Or %WS_Ex_RightScrollbar Control Add Button, hDlg, %BtnTest, "Test", 275, 220, 60, 15 hFont1 = PBFormsMakeFont("Courier New", 9, 400, %FALSE, %FALSE, %FALSE, _ %ANSI_CHARSET) Control Send hDlg, %Lbx, %WM_SETFONT, hFont1, 0 Dialog Show Modal hDlg, Call ShowDlg1Proc To lRslt DeleteObject hFont1 Function = lRslt End Function
Leave a comment: