[10 Feb 2009] Enhanced list handling - is this something that could be implemented?
Posted: Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 10 Feb 2009 20:18:13 -0000
Hi
A wish for enhanced functionality when handling lists. Could something like this be implemented? (Pls. see included code for a practical example of what I have in mind).
Recently I found myself in need of some added functionality for handling lists of items beyond what is currently available as built- in functions in Hollywood 3.x. In effect I needed a linked list where each link knew the link before and the link after in a closed loop (very handy for managing taborders among user controls for one thing). The start of the list would then simply be declared by a pointer to one item in the list that could be changed at any time. Further ther would be a counter for the number of items in the list. Finally there would be a way to store the current list being worked on for use as defaultvalue. Each item in the list has a sublist with a 'previous' and a 'next' value and indexed by the name of the object. These values refers to the indexnames of the actual objects, which are stored in another 'objects' list.
I created a number of functions for managing such lists as follows:
The main trick as I see it for doing it this way is that you have absolute control over the order of items and may reference them by stringnames. Also you can shift the relative order of the elements around easily. By providing sensible defaults populating, managing and depopulating the lists can be done with little code.
A small example:
Assume you have three objects as in Object={"No1","No2","No3"}
To delete all objects in the list we would simply do this:
If you need the object next to object["No2"] in the current list you just ask for:
To get the name of the first object you say:
The last object in the list can be had by:
I have put up the code I have used to implement it including some example code for use in a file called 'linklist_include.hws' in the folder 'JSPGui v1.0x'. It should run directly.
Hi
A wish for enhanced functionality when handling lists. Could something like this be implemented? (Pls. see included code for a practical example of what I have in mind).
Recently I found myself in need of some added functionality for handling lists of items beyond what is currently available as built- in functions in Hollywood 3.x. In effect I needed a linked list where each link knew the link before and the link after in a closed loop (very handy for managing taborders among user controls for one thing). The start of the list would then simply be declared by a pointer to one item in the list that could be changed at any time. Further ther would be a counter for the number of items in the list. Finally there would be a way to store the current list being worked on for use as defaultvalue. Each item in the list has a sublist with a 'previous' and a 'next' value and indexed by the name of the object. These values refers to the indexnames of the actual objects, which are stored in another 'objects' list.
I created a number of functions for managing such lists as follows:
Code: Select all
linklists.new (linklistname$) - this creates a new list
linklist.addlink (id$,oldid$,linklistname$) - adds a link to a list before object(oldid$)
linklist.removelink(id$,linklistname$) - removes a link (and thus references to an object) from the list.
linklist.movelink(id$,targetid$,linklistname$) - moves a link to location just before link identified by targetid$
linklist.swaplinks(id1$,id2$,linklistname$) - swaps location of two links
linklists.getnextlink (id$,linklistname$) - Returns next link after link identified by id$ (or last link by default)
linklists.getpreviouslink(id$,linklistname$) - Returns previouslink before link identified by id$ (or first link by default)
linklists.getlinkcount(linklistname$) - Returns number of links in list.
linklists.setfirstlink(id$,linklistname$) - Sets pointer to first link in the list.
A small example:
Assume you have three objects as in Object={"No1","No2","No3"}
Code: Select all
linklists.new("MyList") This creates a new (empty) list identified by "MyList" and sets the currentlistname$ to "MyList"
linklist.addlink("No2") Adds an entry for object["No2"] in our current list as its last item.
linklist.addlink("No3") Adds another entry at the end.
linklist.addlink("No1","No2") Adds and entry for object["No1"] before the entry for object["No2"] in our current list.
Code: Select all
While linklists.getlinkcount > 0
linklists.removelink() /* Removes the last link in the current list */
Wend
Code: Select all
linklists.getnextlink("no2")
Code: Select all
linklists["MyList"].first$ /* (since 'first$' is the pointer to the first link) */
linklists.getpreviouslink() /* another way of getting the first link using a default */
Code: Select all
linklists["MyList"][first$].prev$ (Remember it is a closed loop so last and first are next to each other)
linklists.getnextlink() /* Another way of getting the last link using a default */