Array of unique values ?

Creating a macro - Writing a Script - Using the API

Array of unique values ?

Postby BubikolRamios » Sat Mar 03, 2018 9:38 pm

Is there predefined object in OO basic that is defined as array of unique values, so that, like :
array.add ("a") --> "a" added
array.add ("a") --> nothing added

I expect array will be huge, rolling thru it to check each time adding, if elemet is already in, would be a pain ....
OPen office 4.1.5/ win 7
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: Array of unique values ?

Postby JeJe » Sun Mar 04, 2018 1:06 am

You can use a Collection. See the later posts on this thread.

https://forum.openoffice.org/en/forum/v ... =20&t=2953
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 552
Joined: Wed Mar 09, 2016 2:40 pm

Re: Array of unique values ?

Postby JeJe » Sun Mar 04, 2018 1:15 am

To check if an item with a given key is already in the collection you need an error trap.
Some versions of this to try are here (VB6 is similar to OOBasic).

https://stackoverflow.com/questions/406 ... collection
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 552
Joined: Wed Mar 09, 2016 2:40 pm

Re: Array of unique values ?

Postby RPG » Sun Mar 04, 2018 11:33 am

LibreOffice 6.1.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2167
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Array of unique values ?

Postby JeJe » Sun Mar 04, 2018 1:50 pm

You can also keep the array sorted or else keep a sorted index into the array - a binary search algorithm is a very efficient way of finding something in a sorted list. You don't need to reinvent the wheel: search for VB6 (similar to OO and a much bigger code base out there) along with your search term - you might need to do a little adapting. Here are some sorting algorithms:

http://www.vbforums.com/showthread.php? ... ing-arrays)

But I'd use a collection... they're very simple to use...
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 552
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests