does Xojo have LinkLists or set functions

Does Xojo have built-in functions to create, add-to, delete, and clean up Linked List (single or double linked) structures?

Does Xojo have functions that work with sets? For example, creating a set that has letters or numbers as elements like A, B, C D in a set with the ability to add or delete elements. Then check if some value X is in the set, or not in the set. Or if you have two sets, create a third of only elements common to the first two. Or adjust a third populated set so it doesn’t contain elements that are in two other sets - that type of action.

It seems I could do that with arrays but I was wondering if the tools already existed and would be more efficient because of more primitive level coding.

I’ve seen “dynamic” arrays where you add - extend - the array one element at a time but I’m not sure about reducing the size of that array if an element needs to be removed; especially from the middle.

no, use arrays.
Or make your own class with a next item field.

Have a look at “Pairs” in the language reference. These can be used to implement LISP style linked lists.

Xojo-tutorial for linked list:
https://www.youtube.com/watch?v=3AWMU-nsbOU

While using classes to create linked lists may be worthwhile, especially if you wish to include some methods to do some specific things related to your application, classes are not necessary for creating linked lists. As I mentioned in my previous post, a pair is sufficient.
Set the lefthand side of a pair to the node’s value, and set the righthand side to another pair which is the next node in the list. Set the lefthand side of that pair to your second node value and the righthand side to another pair which will be the third node, and so on.

It just doesnt extend well is all
If you need more than a single value in each node you have to “do something else” OR write custom methods that are not part of a “node” to have more than that single value
And since your single value is a variant you can deliberately, or accidentally, shove anything in that left hand side and the compiled will never complain you’ve misused your list

I like the compiler complaining at me that i’ve misused things
It helps catch bugs earlier than runtime

I’ve been able to solve all of the problems that I used to use linked list constructs in other languages using dynamic arrays in Xojo.

Using dynamic arrarys, is it easy to remove/resize from the middle or end of the “list”. I’ve seen and understood adding to an array but I haven’t seen, or recall - been a while since I visited the topic - the process of removing elements such that UBound is adjusted to the new size.

The array and Pairs would be handy when dealing with one value; content = 1,2, 3 or A, B, C. What if you wanted each “element” to be more of a “record” with both string and numeric value (like Name and phone number). I understand multi dimensional arrays if all character content or numeric content.

It is just a matter of having multiple dynamic arrays - one numeric, one Character - and just processing the index of both for additional elements, changing values, deleting elements?

Thank you for the YouTube and video reference. One thing not covered - I’m sure it’s language/compiler dependent - is clean up. With today’s RAM capacity, I don’t think space for my little application will be a problem. But the lists I have in mind will be expanding and contracting (hence my lean towards linked lists). As a good citizen, I’d like to clean up any “mess” at the appropriate time. Or even have a warning if I am near the “edge of the cliff” memory-wise.

Is there a mechanism for cleanup or do I go boldly forward, knowing I won’t possibly use the GB’s that will be available during the time the application is running. Can I assume everything is reset once the app closes.

To remove a single item from the array use .Remove(index).
To reduce the size of the array (remove everything from index to the end) use Redim.

Make a class that contains the elements and use that in the pair or array. Instantiate them as you need them.

When you remove something, the memory will be freed, but the system may not reclaim in immediately. But it will be reused.[quote=487206:@Paul Chance]Is there a mechanism for cleanup[/quote]
When you remove all the references to a thing, it will be destroyed and its memory freed immediately. As long as you’re not holding on to references, and you don’t create circular references, you don’t have to worry about it.

Tim, thank you. I understand the dynamic better now.

To give some context, to my interest in LinkedLists, imagine a “hobby” class cipher method called KEYPHRASE.
With that method, unlike polyalphabet ciphers that used multiple cipher text (CT) letters for a single plain text (pt) letter, the keyphrase is such that a single cipher letter can represent multiple plain text letters as in:
CT WOWWHATAGOODBOYAREYOUTODAY
pt ABCDEFGHIJKLMNOPQRSTUVWXYZ - usually represented in lower case.

They don’t line up because of the font but the cipher letters W,O,A,T,Y could each represent any one of several pt letters. When ever the cipher letter “O” appears, it could be one of six plain text letters.

In decrypting the cipher - without the keyphrase itself - in the beginning, any cipher text letter could represent one of more of 26 letters (assuming English language). As guesses are made, a plain text letter is assigned to a specific cipher letter. Remember, a cipher letter can have more than one plain text letters assigned to it. More importantly, it removes that plain letter from the list of candidates for all the other cipher letters. As the candidate letter lists get smaller, so do the lists of potential English words that would match the remaining candidate letters.

Eventually, the letter list becomes small enough so all possible letter combinations can be generated and matched against a dictionary of English words. There would only be a few letter combinations that match words. Now the candidate word list is small enough that the correct word could be guessed from context.

While the user is making the guesses, the program is adjusting lists of letters and eventually lists of words. A correct guess reduces the other lists. Turn a letter “back in”, the lists get larger.

I suppose I could use a two dimensional array were one cell would contain a letter and the other cell would be a “marker” character letting me know if the letter was still a candidate.

Or, with one dimension, I could add 26 to the ASCII value . Then, if the ASCII value is out of the A-Z (capital) range, it isn’t a candidate anymore. To make it a candidate again, I’d subtract 26 from the ASCII value.

But LinkLists seem to just match my mental picture. And it’s a tickle to start imagining a non-linear representations - lists linked to lists.

The way to implement linked lists in Xojo is to create a class that has all the properties you need to hold, plus a property that holds a reference to the next element in the list. Xojo doesn’t have any built-in functionality to help with this. I have used linked lists extensively in other languages, but I haven’t used a language with anything built in. The recursive functions you create for handling lists can be very elegant indeed.

Be aware, though, that you can easily hit memory limits due to recursion in the main thread. The stack size is fixed for the main thread. If you do your processing in a Thread object, you can increase the stack size and avoid overflow.