Notifications
Clear all

[Closed] makeUniqueArray with integers trick

It’s not fantastic but perhaps it’s useful for someone…

‘makeUniqueArray’ for an array of integers is slower than converting the array to bitArray and then convert it back to Array.
Moreover, for the same price, you get your array sorted.

 (
	fn setRandomArray =		
	(
		theArray = #()
		for i = 1 to 500000 do
		(
			append theArray (random 10000 10020)
		)
		return theArray
	)
				
				
	t = timestamp()
		theArray = makeUniqueArray (setRandomArray()) 
	t1 = timestamp()
	format "MXS1 took		%s
" ((t1 - t)*.001)
	format "theArray= %
" theArray
	
	t2 = timestamp()
		theArray = ((setRandomArray()) as BitArray) as Array 
	t3 = timestamp()
	format "MXS2 took		%s
" ((t3 - t2)*.001)
	format "theArray= %
" theArray
	OK
)			

4 Replies
 lo1

It’s all fun and games until your array is #(1, 2, 3, 9999999999)

2 Replies
(@aaandres)
Joined: 11 months ago

Posts: 0

Yes for sure. I was thinking in an array of verts or faces.

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

Good point. For that purpose it should always work well.

all depends on size of original array and values in it.

(
	t = timestamp()
	m = heapfree
	arr = (#(1, 999999999) as bitarray) as array
	format "% => time:% memory:%
" arr (timestamp() - t) (m - heapfree)
) 
(
	t = timestamp()
	m = heapfree
	arr = makeuniquearray #(1, 999999999)
	format "% => time:% memory:%
" arr (timestamp() - t) (m - heapfree)
)