We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LDArray extension
#1
Hi All...

This may seem like a dumb question... but

Having trouble understanding how to use the LDarray extension.  There is no examples, do you think you can give me some example?

I am having trouble to even create one using the ldarray extension, normal Sb array is fine, but just don't seem to get ldarray to work.

Thanks you all for helping and your time in advance.

Regards
Reply
#2
Hi Yumda,

Thanks for your question.

We know that SB arrays can be slow or even very slow for large, espacially multi-dimensional arrays.

For 1D arrays I recomment using LDList - this is fast, effiecient, easy to add, remove, sort etc and you don't have to set the max dimension size to start with (its a dynamic sizing list).

LDFastArray is designed for multi-dimansional arrays.

So, back to LDArray, which is the fastest 1D array (in C# anyway), I still probably recommend LDList since it is more flexible and probably similar performance in SB.

If you want a specific example and one of the methods, then ask, but here is a simple example of its use.

Code:
dim = 10000
array = LDArray.Create(dim)
For i = 1 To dim
  LDArray.SetValue(array,i,Math.GetRandomNumber(dim))
EndFor
TextWindow.WriteLine("Array created")
LDArray.Sort(array)
TextWindow.WriteLine("Array sorted")
For i = 1 to 10
  TextWindow.WriteLine(LDArray.GetValue(array,i))
EndFor


So, depending on your use, I recommend LDList for 1D, LDFastArray for multi-dimensional lists, and if you want to use LDArray and have specific questions on it, then please ask.
Reply
#3
how does LDarray.createfromvalue work?  in order to set it up do I still need to set the dimension as well?

What I am trying to do is to read a list of items from a txt file, and be able to add or remove the item then write back the list. 

In Ldlist.copy , it says it will copy from a list, do you need to declare a new list first or can it read from the file directly? or LDlist.createfromvalue , do we need to make a small basic array first?

Regards

This is what I did as a test

vocabList[1] = "alpha"
vocabList[2] = "Beta"
vocabList[3] = "Zeta"
vocabList[4] = "Eta"

newarray = LDList.CreateFromValues(vocabList)

some how it does not have any values..

what am I doing wrong here?
Reply
#4
LDFile.ReadToArray
Will make a sb array but you could make it to ldlist or ldarray
ZS
Reply
#5
(11-18-2024, 01:34 AM)Yumda Wrote: how does LDarray.createfromvalue work?  in order to set it up do I still need to set the dimension as well?
...

(translated by Google translator)

Hello, Yumda  Shy

It seems to me that you do not know this link: https://litdev.uk/LitDev.html

It says there: " LDarray.CreateFromValues(sbArray) - Create a new array from the values of a Small Basic array. "

Look at this data. If this does not help you, then be sure to let us know. We will be happy to tell you everything we know.  Smile

(11-18-2024, 01:34 AM)Yumda Wrote: ...
What I am trying to do is to read a list of items from a txt file, and be able to add or remove the item then write back the list.
...

LDList.Read(filePath) - Read a list from a file. returns: The list name if the operation was successful, otherwise "".
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
#6
I am trying to understand the LDlist Objects, here is what I am confused about:
vocabList[1] = "alpha"
vocabList[2]= "Beta"
vocabList[3]= "Zeta"
vocabList[4] = "Eta"

newarray = LDList.Copy(vocabList)

textwindow.writeline(LDList.Count(newarray))

what I am confused is that the textwindow would come back that it is "0"

However. if using LDlist.createfromvalue, then LDlist.count will come back as 4, but if I tried to print the value in textwindow, there is nothing.
this is the test code I tried:
for i = 1 to ldlist.count(newarray)
textwindow.writeline(newarray[i])
endfor


So, what am I doing wrong here?
Reply
#7
(11-18-2024, 11:23 PM)Yumda Wrote: I am trying to understand the LDlist Objects,  here is what I am confused about:
vocabList[1] = "alpha"
vocabList[2]= "Beta"
vocabList[3]= "Zeta"
vocabList[4] = "Eta"

...

So, what am I doing wrong here?

(translated by Google translator)

Hello Yumda.  Shy
It seems to me that you are not looking at the information that is in the link: https://litdev.uk/LitDev.html

You initialize the first element of the vocabList[1] array in the same way you would use to work with a regular SB array: vocabList[1] = "alpha"

But, you want to have a LIST, not a SB array. Therefore, you should use methods that are designed to work with a LIST.

LDList.Add(vocabList, "alpha")
LDList.Add(vocabList, "Beta")
LDList.Add(vocabList, "Zeta")
LDList.Add(vocabList, "Eta")

( I will continue later )  Smile
Reply
#8
Yumba,

You write: newarray = LDList.Copy(vocabList)

When the "vocabList" object was a SB array, this code did not work because the LDList.Copy() method is designed to create a copy of a LIST, not a SB array. Now that we have created a LIST named "vocabList", the LDList.Copy() method will work correctly.  Shy
Reply
#9
Yumba,

I know of 4 array types in Small Basic:
- - - - -
sbArrayName[i] = x;  ( sbArrayName[i][j] = x ) - slow one-dimensional and multi-dimensional arrays;

arrayName = LDArray.Create(maxSize);  ( LDArray.SetValue(arrayName, i, x) ) - the fastest one-dimensional array;

fastArrayName = LDFastArray.Add();  ( LDFastArray.Set(fastArrayName, i , x) ) - fast multi-dimensional array;

LDList.Add(listName, x);  ( LDList.SetAt(listName, i, x) ) - fast and convenient type.
- - - - -

Each of these types has its own advantages and disadvantages.
You can choose the type that best suits your task.

Shy
Reply
#10
AbsoluteBeginner:

Thank you very much for the explanation, I guess I did not fully understand the meaning of the List. Now that you have explained it, it makes sense. I still have a few question.

1. when using ldlist.add, you type out each individual value, is there anyway to make a few words in a list and add all at once?

2. It seems there are indices in the list, what is the list structure looks like when we actually write it out?

Thanks for helping.

Regards
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)