Jump to content

Chain Structure Include Script


Guest Mixture63
 Share

Recommended Posts

Guest Mixture63

Requires Mx63.dll plugin - The link is in my sig.

This very simple include script lets you create chains of links. Links are good because you can attach them and then easily remove one link and place it somewhere else. Links can contain values. If you know how to use my plugin you will be able to store strings in these chains. Each chain has 4 flags which can have values from 0 to 255. It is zero-indexed.

There are instances in which chains may be useful.

With creativity you can create more complicated structures that include child and parent links.

Now the chains only support back and next and value. But with the flags and value you can make it more complicated. You can make more complicated data structures for all different kinds of things.

You can store strings in links by using StringStore() from the plugin to allocate space for a string and gets its address and put that value in the link. Then on chain destruction you can use StringFree() to do the oppisite.

Chain.au3

Edited by Mixture63
Link to comment
Share on other sites

A tree data structure:

func TreeElementCreate()
    $ea = BufferAllocate(24)
    BufferWriteInt($ea, 0)
    BufferWriteInt($ea+4, 0)
    BufferWriteInt($ea+8, 0)
    BufferWriteInt($ea+12, 0)
    BufferWriteInt($ea+16, 0)
    BufferWriteInt($ea+20, 0)
    return $ea
EndFunc

func TreeElementDelete($Address)
    BufferFree($Address, 24)
EndFunc

func TreeElementAttachLeft($Element, $NextElement)
    TreeElementSetLeft($Element, $NextElement)
    TreeElementSetParent($NextElement, $Element)
EndFunc

func TreeElementDettachLeft($Element)
    TreeElementSetParent(TreeElementGetLeft($Element), 0)
    TreeElementSetLeft($Element, 0)
EndFunc

func TreeElementAttachRight($Element, $NextElement)
    TreeElementSetRight($Element, $NextElement)
    TreeElementSetParent($NextElement, $Element)
EndFunc

func TreeElementDettachRight($Element)
    TreeElementSetParent(TreeElementGetRight($Element), 0)
    TreeElementSetRight($Element, 0)
EndFunc

func TreeElementGetValue($Address)
    return BufferReadInt($Address)
EndFunc

func TreeElementSetValue($Address, $Value)
    BufferWriteInt($Address, $Value)
EndFunc

func TreeElementGetRight($Address)
    return BufferReadInt($Address+4)
EndFunc

func TreeElementSetRight($Address, $Value)
    BufferWriteInt($Address+4, $Value)
EndFunc

func TreeElementGetLeft($Address)
    return BufferReadInt($Address+8)
EndFunc

func TreeElementSetLeft($Address, $Value)
    BufferWriteInt($Address+8, $Value)
EndFunc

func TreeElementGetParent($Address)
    return BufferReadInt($Address+12)
EndFunc

func TreeElementSetParent($Address, $Value)
    BufferWriteInt($Address+12, $Value)
EndFunc

func TreeElementSetParam1($Address, $Flag)
    BufferWriteInt($Address+16, $Flag)
EndFunc

func TreeElementGetParam1($Address)
    return BufferReadInt($Address+16)
EndFunc

func TreeElementSetParam2($Address, $Flag)
    BufferWriteInt($Address+20, $Flag)
EndFunc

func TreeElementGetParam2($Address)
    return BufferReadInt($Address+20)
EndFunc
Edited by nfwu
Link to comment
Share on other sites

Guest Mixture63

There is just one error in your code.

Your allocating 24 bytes (correct) but you freeing 28 bytes (incorrect).

The amount you free should be = to the amount you allocate.

Link to comment
Share on other sites

Guest Mixture63

You have linked lists(like your chain), queues, stacks, trees, vectors, lists, deque, etc...

You could probably make UDFs for quees and stacks super mega ultra real easy.

Edited by Mixture63
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...