Announcement

Collapse
No announcement yet.

Scanning an Array for an item value = 0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    I'm not sure if you can even adapt your code to use dictionaries but I'll attach some interesting findings. Two PBWin9 examples. One is a severely hacked version of Paul's Hash demo and one is an attempt to duplicate it using an IDictionary. I meant to (and I will) put together a much better example os using IDictionary with the new compilers. José told me that the IDictionary would be faster than the Hash up to 25k items. I forgot a zero in my previous post.

    James
    Attached Files

    Comment


    • #22
      Norbert
      From what you describe I doubt that arrays and array scan are a very efficient method for handling the data. I suggest you build a B tree, finding existing values and reading back in sorted order becomes very fast.
      John

      Comment


      • #23
        Rodney, following is the same sample code like the above one, with slight changes. As I discribed I'm using the resulting array inside a bunch of other routines. I avoided to have to change anything inside the other code. I simply introduced a temporary handle "TempH" which is only used inside this code here where I'm translating 0 to -1 and vice versa. Even with two If..Else..End if there seems to be only a slight deceleration of 1/2 seconds with 86487 entities to be cut and redrawn. This whole process needs now 3.1 seconds instead of 3 seconds. That's fast enough for now.
        PB makes this possible and earns the olympic gold medal!
        Code:
        '-------------------------------------------------------------------------------------------------------
        ' FUNCTION EntitiesCrossingFence
        '-------------------------------------------------------------------------------------------------------
        Function EntitiesCrossingFence(dpFence() As POINT2D, CrossingH() As Long) As Long
        	'Handles von Elementen auflisten, die den Zaun kreuzen
        	'INPUT: dpFence() = Array mit den Zaunpunkten, tfSelClosed = unter der geschlossenen Kontur wird ebenfalls selektiert 
        	'OUTPUT: CrossingH) = Handle-Liste der kreuzenden Elemente
        	'Function = Anzahl der kreuzenden Elemente
        	Local i As Long
        	Local n As Long
        	Local iError As Integer
           Local iSeg As Long
           Local iRet As Long
           Local iEntKind As Integer
           Local iCount As Long
           Local EntH As Long
           Local iFencePts As Long
           Local TempH As Long
           Dim dpSeg() As POINT2D
           
        	Function = 0   
        	ReDim CrossingH(0)
        	VCDeselectAll()
        	iFencePts = UBound(dpFence) 'Anzahl der Zaunpunkte
           'Prüfen, ob die selektierten Elemente eines der Zaunsegmente schneiden.
        	iSeg = 200 'Anzahl der zu erzeugenden Segmente entlang jeder Selektionskontur von dpFence
        	iCount = 0
        	For i = 0 To iFencePts - 2
        		ReDim dpSeg(iSeg) 'Array der zu erzeugenden Punkte
        		iRet = maDivideLinePnt(dpFence(i), dpFence(i + 1), iSeg, dpSeg()) 'Auf dem Selektionssegment dpFence(i) iSeg Minisegmente erzeugen
        		For n = 0 To iSeg - 1 'mit den erzeugten Segmenten als Kette von kleinen Selektionsfenstern kreuzend selektieren
        			MCCrossingSelect(dpSeg(n), dpSeg(n+1))
        			If MCSelectedFirst(iError, iEntKind) Then
        				Do While iError = 0
        				   MCSetCurrentDeselected(iError)
        					If iEntKind <> %UNKNOWN Then
        						EntH = MCGetCurrEntHandle(iError)
        						If EntH = 0 Then 
        						   TempH = -1
        						Else
        						   TempH = EntH
        						End If
                          iRet = 0						
        						If UBound(CrossingH()) > 0 Then
        						   Array Scan CrossingH(), =TempH, To iRet 'iRet zählt mit der Basis 1, CrossingH mit der Basis 0
        						End If
                          If iRet = 0 Then 'Wenn iRet = 0, dann ist Element EntH noch nicht in CrossingH() enthalten, dann in CrossingH() sichern
        						   ReDim Preserve CrossingH(iCount + 1)
           						If TempH = -1 Then 
           						   EntH = 0
           						Else 
           						   EntH = TempH
           						End If
        						   CrossingH(iCount) = EntH
        						   iCount = iCount + 1
        						End If
        						If MCSelectedNext(iError, iEntKind) Then
        						End If 
        					End If
        				Loop
        			End If
        		Next n
        		ReDim dpSeg(0) 'zurücksetzen
        	Next i
        	Function = iCount
        End Function
        Norbert Doerre

        Comment


        • #24
          Norbert,

          As of now I still have not received my PB 9, where apparently you found this issue.

          The guy that ordered it for me chose the delivery method that would result in the longest delivery period. I would fire him but he's an integral part of, well he's related.
          Rod
          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

          Comment

          Working...
          X