• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Add to list but can never remove

GW_

New member
Joined
Jul 5, 2017
Messages
5
'TEST
Local L:List<float[] > = New List<Float[] > ()
L.AddFirst(New Float[2])
Local fa:Float[] = L.First()
L.Remove(fa)


Error: Arrays cannot be compared
 
This seems to be kind of a missing functionality due to the fact that it is ambiguous under which cirumstances arrays are equal. Do you need the reference to be equal or the content?

What do you want to achieve? Do you only need it to remove the first array or do you want to remove an arbitrary one?
 
I don't understand your questions. The title of the post and the example explain everything.

Do you need the reference to be equal or the content?
I need to remove an item from the list.

What do you want to achieve?
Remove an item from the list.

Do you only need it to remove the first array or do you want to remove an arbitrary one?
It doesn't matter. An item cannot be removed from the list once it's added.
 
Yes, items can be removed. The problems are Arrays and the way you want them to be removed. Arrays can currently only be removed via their ListNode which will be returned when you add an item to a list and you need to store that Node somewhere. Then it is simply a call

Cerberus:
yourNode.Remove()

That is by far the fastest way to remove a node from a list.

The call of List.Remove(item) loops through the whole list and trys to find ALL items that are equal and deletes them. The problem with arrays is that a comparison for ARRAYS is currently not implemented. We have an idea how to do it, but it might not work anyway.
 
I need to remove an item from the list.
If you don't mind the content to be compared it might be better using a List of Lists instead of a List of arrays.

For your special example something like this works:
Code:
Strict

Function Main:Int()

    Local L:List<Float[]> = New List<Float[]>()
    Local arr1:Float[]=[1.0,2.0]
    Local arr2:Float[]=[3.0,4.0]
    Local arr3:Float[]=[1.0,2.0]
    
    Print L.Count() + " Arrays left."
    
    L.AddFirst(arr1)
    L.AddFirst(arr2)
    L.AddFirst(arr3)
    Print L.Count() + " Arrays left."
    
    Local foundNode:list.Node<Float[]>
    foundNode = L.FirstNode()
    If foundNode foundNode.Remove
    foundNode = L.FirstNode()
    If foundNode foundNode.Remove
    Print L.Count() + " Arrays left."

    Return 0
End
 
Another way would be to wrap the array in a class and have a comparison for the class.
 
Back
Top Bottom