ListID(list())

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Psych
Enthusiast
Enthusiast
Posts: 239
Joined: Thu Dec 18, 2008 3:35 pm
Location: Wales, UK

ListID(list())

Post by Psych »

It would be useful to know if a certain list (passed in a parameter for example) is the same as another list.

Right now the only solution (as far as I know) is to wrap the list in a structure and use the pointer to that structure variable (thanks to @Idle for this tip).

I am sure the list size is cached, so this being the case could we not get a pointer to this secret cached area? We could then use this pointer to determine if 2 lists are the same (or not).

Code: Select all

*uniqueID - ListID(list())
----------------------------------------------------------------------------
Commenting your own code is admitting you don't understand it.
----------------------------------------------------------------------------
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: ListID(list())

Post by AZJIO »

The lists differ by name. Their name is their identifier. To check the sameness of lists, you need to compare their size and then compare their data, that is, compare the elements of the list. There is already a function for this: CompareList(List1() , List2() [, Flags])
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: ListID(list())

Post by DarkDragon »

AZJIO wrote: Tue Oct 22, 2024 6:17 am The lists differ by name. Their name is their identifier. To check the sameness of lists, you need to compare their size and then compare their data, that is, compare the elements of the list. There is already a function for this: CompareList(List1() , List2() [, Flags])
OP wants to know whether their reference equals, not their value. You can pass the same list as two arguments to a procedure.
bye,
Daniel
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: ListID(list())

Post by AZJIO »

DarkDragon wrote: Tue Oct 22, 2024 6:29 am You can pass the same list as two arguments to a procedure.
It's clear.
In any case, CompareList() most certainly checks the pointer and will not compare the same list. Moreover, CompareList() shows that the lists are the same.

It doesn't throw an error

Code: Select all

Debug CompareList(list1() , list1())
I tried to check the previous data, but got nothing. Perhaps they have a different address.

Code: Select all

Define NewList list1()

AddElement(list1())
list1() = 255

byte = 32
ShowMemoryViewer(@list1() - byte, byte  + 2)
Got the number

Code: Select all

Define NewList list1()
c=3 ; 1-16

For i = 1 To c
	AddElement(list1())
	list1() = 255
Next

byte = SizeOf(Integer) * c * 4 + 4
*x.Integer =  @list1() - byte
Debug *x\i
ShowMemoryViewer(@list1() - byte - 2, byte  + 4)
Psych
Enthusiast
Enthusiast
Posts: 239
Joined: Thu Dec 18, 2008 3:35 pm
Location: Wales, UK

Re: ListID(list())

Post by Psych »

AZJIO wrote: Tue Oct 22, 2024 7:00 am Got the number
I was sure there was a way to do this, given lists have cached values, I was just hoping there would be a way to have this added natively, and ListID() would fit nicely with existing keywords.
By the looks of it, not much extra coding required.
Could also add a MapID() if possible too.
----------------------------------------------------------------------------
Commenting your own code is admitting you don't understand it.
----------------------------------------------------------------------------
Post Reply