# User:Decimus Schomer/Scripts/Libraries/LSL sets

## Script

```// LSL set library
// Copyright (C) 2007 Decimus Schomer
//
// This program is free software; you can redistribute it and/or modify
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

////////////////////////////////////////////////////////////////////////////////
// Multi-dimensional array library (required for multi-dimensional sets)

list mda_val_lens;
list mda_val;

integer mda_len(integer idx)
{
if (idx == -1)
return llGetListLength(mda_val_lens);
return llList2Integer(mda_val_lens, idx);
}

////////////////////////////////////////////////////////////////////////////////
// Set library

{
if(val != [0]) // Only want single entry lists. (Comparing lists compares list length; comparison is faster than length checking)
{
return set;
}
if(!~llListFindList(set,val))
{
set = (set=[])+set+val;
}
return set;
}

{
integer lenv = llGetListLength(val);
string csvv = llList2CSV(val);
integer x;
integer y;
list l;
integer s = 0;
integer d;
integer mlen = mda_len(-1);
for (y = 0; y < mlen; ++y)
{
d = llList2Integer(mda_val_lens, y);
if (d == lenv)
{
l = llList2List(mda_val, s, s+d);
for (x = 0; x < d; ++x)
{
// It's safe to compare anything as a string, excluding floats that you want accurate to more than six significant figures.
// You can't really compare those anyway.
if (llList2CSV(l) == csvv)
{
return;
}
}
}
s += d;
}
mda_val += val;
mda_val_lens += [lenv];
}

list list_to_set(list l)
{
list copy = [];
integer i;
integer len = llGetListLength(l);
for (i = 0; i < len; ++i)
{
if(llGetListEntryType(l, i) == TYPE_INTEGER)
{
}
else if(llGetListEntryType(l, i) == TYPE_STRING)
{
}
}
return copy;
}

mda_to_set()
{
integer len = mda_len(-1);
list orig_lens = mda_val_lens;
list orig = mda_val;
mda_val_lens = [];
mda_val = [];
integer i;
integer s;
integer d;
list l;
for (i = 0; i < len; ++i)
{
d = llList2Integer(orig_lens, i);
l = llList2List(orig, s, s+d);
s += d;
}
}

// Compatability functions
{
}

{
}

list int_list_to_set(list l)
{
return list_to_set(l);
}

list str_list_to_set(list l)
{
return list_to_set(l);
}

str_mda_to_set()
{
mda_to_set();
}

int_mda_to_set()
{
mda_to_set();
}

{
}