[Coco] sorting Delphi messages

Roger Taylor operator at coco3.com
Tue Sep 15 01:13:28 EDT 2009


At 11:52 PM 9/14/2009, you wrote:
>I think you're heading in the right direction. The only way to 
>really preserve the threads is to load the bulk of the messages in 
>its entirety into either a database or a dictionary in memory. The 
>database idea might work, but then it becomes a monstrous task to 
>rebuild the threads back to a single parent since the nesting level 
>is potentially infinite. Even though it's possible, it's not likely 
>worth the effort unless you load all the Message Ids into something 
>like a balanced tree or a red-black tree (basically a self-balancing tree).
>
>If I remember those thread correctly (bearing in mind it's been 
>something like 20 years since I've look at them), most of the 
>threads are relatively short so it shouldn't be much of a problem to 
>ignore the extreme cases.
>
>Let me know if you need any help with them and I'll do what I can.

Sometimes the simplest solutions work wonders, but we'll see in this case.
The below snippet is producing a promising list of msg IDs sorted by 
parent ID.  Whether or not the first routine is needed or not, I 
don't know yet.. it was a quick first attempt of inserting the posts 
at the right indexes in the new table.  If a post is inserted after 
it's parent, then unlimited nesting would be handled, but when it 
comes time to XML this stuff, the ID #'s have to be converted to 
0-based IDs for the WordPress comments.  I'm nearing that chore 
probably tomorrow.  If all goes well enough, threading should be recovered.


    ' find all Thread Starters and add to new list
         For Each msgitems In Posts
             key = Val(msgitems.Key)
             foundmsg = CType(Posts(key), Msg)
             If foundmsg.Sorted = False Then
                 If foundmsg.Parent = 0 Then
                     foundmsg.Sorted = True
                     Threads.Add(foundmsg)
                     report &= "Sorted Thread Starter " & foundmsg.ID 
& " into new list " & vbCrLf
                 End If
             End If
         Next

         ' find all Replies and insert them after their parent ID in 
the new list
         For Each msgitems In Posts
             key = Val(msgitems.Key)
             foundmsg = CType(Posts(key), Msg)
             If foundmsg.Sorted = False Then
                 If foundmsg.Parent > 0 Then
                     parentkey = foundmsg.Parent
                     parentmsg = CType(Posts(parentkey), Msg)
                     parentidx = Threads.IndexOf(parentmsg)
                     If parentidx < 0 Then
                         parentidx = 0
                     End If
                     foundmsg.Sorted = True
                     Threads.Insert(parentidx, foundmsg)
                     report &= "Sorted Reply " & foundmsg.ID & " into 
new list " & vbCrLf
                 End If
             End If
         Next



-- 
~ signature section for all e-mails-
~ While I have seen Many annoying taglines over the years, I've never 
really complained, but here's mine:
~ Roger Taylor
~ http://www.americafedup.com



More information about the Coco mailing list