Array types with unique funtion

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Array types with unique funtion

Tim Taplin
I cant find this in the reference guide but I could be missing  
something.  Are there any array or map types that have a unique  
element function? I'm trying to simplify the unique merge of several  
arrays of pairs.

currently creating a temparray and inserting only items which are not  
already present and using that as a key reference for the maps which  
hold the data. I would love to create the temparray without using an  
iterate loop although I suppose that is what would happen in the  
background of a tag anyway.

Any thoughts?

Thanks

Tim Taplin

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Fletcher Sandbeck-3
On 8/28/08 at 2:44 PM, [hidden email] (Tim Taplin) wrote:

>I cant find this in the reference guide but I could be missing
>something.  Are there any array or map types that have a unique
>element function? I'm trying to simplify the unique merge of several
>arrays of pairs.
>
>currently creating a temparray and inserting only items which
>are not already present and using that as a key reference for
>the maps which hold the data. I would love to create the
>temparray without using an iterate loop although I suppose that
>is what would happen in the background of a tag anyway.

The [Set] type will maintain a unique set of elements.  If you
insert an element that is already in the set it will be
ignored.  Otherwise, the set type works just like an array.

set(1, 2, 3, 4, 1) ==> set: 1, 2, 3, 4

You could also explore the [Set] type to merge your arrays of
pairs.  The latter inserts will be ignored if the element is
already in the set.

local('set') = set;
#set->insert(1='one');
#set->insert(2='two');
#set->insert(3='three');
#set->insert(1='alpha');
#set;

==> set: pair: (1)=(one), pair: (2)=(two), pair: (3)=(three)

So, to merge a couple arrays of pairs you could do something
like this.

local('numberset') = set;
#numberset->insert(1='one');
#numberset->insert(3='three');

local('greekset') = set;
#greekset->insert(1='alpha');
#greekset->insert(2='beta');

local('set') = set;
#set->insertfrom(#greekset->iterator);
#set->insertfrom(#numberset->iterator);
#set;

==> set: pair: (1)=(alpha), pair: (2)=(beta), pair: (3)=(three)

Hope this helps,

[fletcher]

--
Fletcher Sandbeck                         [hidden email]
LassoSoft, LLC                          http://www.lassosoft.com


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

jasonhuck
FWIW, I am using this subclassed array type in situations where I need
the "uniqueness" of a set, but also need to maintain a specific, but
otherwise arbitrary, order:

http://tagswap.net/array_unique

It's probably not the most efficient implementation, but the data sets
I use it with are pretty small, so performance has, thus far, not been
a problem.

- jason




On Thu, Aug 28, 2008 at 4:59 PM, Fletcher Sandbeck
<[hidden email]> wrote:

> On 8/28/08 at 2:44 PM, [hidden email] (Tim Taplin) wrote:
>
>> I cant find this in the reference guide but I could be missing
>> something.  Are there any array or map types that have a unique
>> element function? I'm trying to simplify the unique merge of several
>> arrays of pairs.
>>
>> currently creating a temparray and inserting only items which are not
>> already present and using that as a key reference for the maps which hold
>> the data. I would love to create the temparray without using an iterate loop
>> although I suppose that is what would happen in the background of a tag
>> anyway.
>
> The [Set] type will maintain a unique set of elements.  If you insert an
> element that is already in the set it will be ignored.  Otherwise, the set
> type works just like an array.
>
> set(1, 2, 3, 4, 1) ==> set: 1, 2, 3, 4
>
> You could also explore the [Set] type to merge your arrays of pairs.  The
> latter inserts will be ignored if the element is already in the set.
>
> local('set') = set;
> #set->insert(1='one');
> #set->insert(2='two');
> #set->insert(3='three');
> #set->insert(1='alpha');
> #set;
>
> ==> set: pair: (1)=(one), pair: (2)=(two), pair: (3)=(three)
>
> So, to merge a couple arrays of pairs you could do something like this.
>
> local('numberset') = set;
> #numberset->insert(1='one');
> #numberset->insert(3='three');
>
> local('greekset') = set;
> #greekset->insert(1='alpha');
> #greekset->insert(2='beta');
>
> local('set') = set;
> #set->insertfrom(#greekset->iterator);
> #set->insertfrom(#numberset->iterator);
> #set;
>
> ==> set: pair: (1)=(alpha), pair: (2)=(beta), pair: (3)=(three)
>
> Hope this helps,
>
> [fletcher]
>
> --
> Fletcher Sandbeck                         [hidden email]
> LassoSoft, LLC                          http://www.lassosoft.com
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>



--
tagSwap.net :: Open Source Lasso Code
<http://tagSwap.net/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Daniel Logue
In reply to this post by Fletcher Sandbeck-3
Sets work almost like arrays... When evaluating them for true and false,
sets seem to turn up false:

[

( set(1) ? true | false ); // --> false
('<br />');
( array(1) ? true | false ); // --> true

]

-----Original Message-----
From: Lasso Talk [mailto:[hidden email]] On Behalf Of
Fletcher Sandbeck
Sent: Thursday, August 28, 2008 1:59 PM
To: Lasso Talk
Subject: Re: Array types with unique funtion

On 8/28/08 at 2:44 PM, [hidden email] (Tim Taplin) wrote:

>I cant find this in the reference guide but I could be missing
>something.  Are there any array or map types that have a unique
>element function? I'm trying to simplify the unique merge of several
>arrays of pairs.
>
>currently creating a temparray and inserting only items which
>are not already present and using that as a key reference for
>the maps which hold the data. I would love to create the
>temparray without using an iterate loop although I suppose that
>is what would happen in the background of a tag anyway.

The [Set] type will maintain a unique set of elements.  If you
insert an element that is already in the set it will be
ignored.  Otherwise, the set type works just like an array.

set(1, 2, 3, 4, 1) ==> set: 1, 2, 3, 4

You could also explore the [Set] type to merge your arrays of
pairs.  The latter inserts will be ignored if the element is
already in the set.

local('set') = set;
#set->insert(1='one');
#set->insert(2='two');
#set->insert(3='three');
#set->insert(1='alpha');
#set;

==> set: pair: (1)=(one), pair: (2)=(two), pair: (3)=(three)

So, to merge a couple arrays of pairs you could do something
like this.

local('numberset') = set;
#numberset->insert(1='one');
#numberset->insert(3='three');

local('greekset') = set;
#greekset->insert(1='alpha');
#greekset->insert(2='beta');

local('set') = set;
#set->insertfrom(#greekset->iterator);
#set->insertfrom(#numberset->iterator);
#set;

==> set: pair: (1)=(alpha), pair: (2)=(beta), pair: (3)=(three)

Hope this helps,

[fletcher]

--
Fletcher Sandbeck                         [hidden email]
LassoSoft, LLC                          http://www.lassosoft.com


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Tim Taplin
In reply to this post by Fletcher Sandbeck-3
thanks for the pointers. Does the iterator function somehow sort  
elements on the way in?

I've tested this with an array of pairs that is presorted into  
descending order using array->sort('false'). Then I use set-
 >insertfrom(array->iterator) to create a unique set which then seems  
to be sorted in ascending order. I tried changing the array->sort  
command as well as using reverseiterator. both returned the same set  
sorted by the pair->first item in ascending order.

I can deal with this is I can rely on it but I wanted to make sure  
this is expected behavior.

Tim
On Aug 28, 2008, at 2:59 PM, Fletcher Sandbeck wrote:

> On 8/28/08 at 2:44 PM, [hidden email] (Tim Taplin) wrote:
>
>> I cant find this in the reference guide but I could be missing
>> something.  Are there any array or map types that have a unique
>> element function? I'm trying to simplify the unique merge of several
>> arrays of pairs.
>>
>> currently creating a temparray and inserting only items which are  
>> not already present and using that as a key reference for the maps  
>> which hold the data. I would love to create the temparray without  
>> using an iterate loop although I suppose that is what would happen  
>> in the background of a tag anyway.
>
> The [Set] type will maintain a unique set of elements.  If you  
> insert an element that is already in the set it will be ignored.  
> Otherwise, the set type works just like an array.
>
> set(1, 2, 3, 4, 1) ==> set: 1, 2, 3, 4
>
> You could also explore the [Set] type to merge your arrays of  
> pairs.  The latter inserts will be ignored if the element is  
> already in the set.
>
> local('set') = set;
> #set->insert(1='one');
> #set->insert(2='two');
> #set->insert(3='three');
> #set->insert(1='alpha');
> #set;
>
> ==> set: pair: (1)=(one), pair: (2)=(two), pair: (3)=(three)
>
> So, to merge a couple arrays of pairs you could do something like  
> this.
>
> local('numberset') = set;
> #numberset->insert(1='one');
> #numberset->insert(3='three');
>
> local('greekset') = set;
> #greekset->insert(1='alpha');
> #greekset->insert(2='beta');
>
> local('set') = set;
> #set->insertfrom(#greekset->iterator);
> #set->insertfrom(#numberset->iterator);
> #set;
>
> ==> set: pair: (1)=(alpha), pair: (2)=(beta), pair: (3)=(three)
>
> Hope this helps,
>
> [fletcher]
>
> --
> Fletcher Sandbeck                         [hidden email]
> LassoSoft, LLC                          http://www.lassosoft.com
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

jasonhuck
Sets sort alphabetically by default, or you can specify a "comparator"
when you initialize the set to adjust how it sorts.

I don't *think* there's a way to maintain a completely arbitrary order
with a set, but I could be wrong about that.

http://docs.lassosoft.com/Lasso%208.5/003%20Language%20Guide/005%20Types/030%20Arrays,%20Maps,%20and%20Compound%20Data%20Types/index.lasso#Sets

- jason



On Thu, Aug 28, 2008 at 8:07 PM, Tim Taplin <[hidden email]> wrote:

> thanks for the pointers. Does the iterator function somehow sort elements on
> the way in?
>
> I've tested this with an array of pairs that is presorted into descending
> order using array->sort('false'). Then I use
> set->insertfrom(array->iterator) to create a unique set which then seems to
> be sorted in ascending order. I tried changing the array->sort command as
> well as using reverseiterator. both returned the same set sorted by the
> pair->first item in ascending order.
>
> I can deal with this is I can rely on it but I wanted to make sure this is
> expected behavior.
>
> Tim
> On Aug 28, 2008, at 2:59 PM, Fletcher Sandbeck wrote:
>
>> On 8/28/08 at 2:44 PM, [hidden email] (Tim Taplin) wrote:
>>
>>> I cant find this in the reference guide but I could be missing
>>> something.  Are there any array or map types that have a unique
>>> element function? I'm trying to simplify the unique merge of several
>>> arrays of pairs.
>>>
>>> currently creating a temparray and inserting only items which are not
>>> already present and using that as a key reference for the maps which hold
>>> the data. I would love to create the temparray without using an iterate loop
>>> although I suppose that is what would happen in the background of a tag
>>> anyway.
>>
>> The [Set] type will maintain a unique set of elements.  If you insert an
>> element that is already in the set it will be ignored.  Otherwise, the set
>> type works just like an array.
>>
>> set(1, 2, 3, 4, 1) ==> set: 1, 2, 3, 4
>>
>> You could also explore the [Set] type to merge your arrays of pairs.  The
>> latter inserts will be ignored if the element is already in the set.
>>
>> local('set') = set;
>> #set->insert(1='one');
>> #set->insert(2='two');
>> #set->insert(3='three');
>> #set->insert(1='alpha');
>> #set;
>>
>> ==> set: pair: (1)=(one), pair: (2)=(two), pair: (3)=(three)
>>
>> So, to merge a couple arrays of pairs you could do something like this.
>>
>> local('numberset') = set;
>> #numberset->insert(1='one');
>> #numberset->insert(3='three');
>>
>> local('greekset') = set;
>> #greekset->insert(1='alpha');
>> #greekset->insert(2='beta');
>>
>> local('set') = set;
>> #set->insertfrom(#greekset->iterator);
>> #set->insertfrom(#numberset->iterator);
>> #set;
>>
>> ==> set: pair: (1)=(alpha), pair: (2)=(beta), pair: (3)=(three)
>>
>> Hope this helps,
>>
>> [fletcher]
>>
>> --
>> Fletcher Sandbeck                         [hidden email]
>> LassoSoft, LLC                          http://www.lassosoft.com
>>
>>
>> --
>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>



--
tagSwap.net :: Open Source Lasso Code
<http://tagSwap.net/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Fletcher Sandbeck-3
In reply to this post by Tim Taplin
On 8/28/08 at 6:07 PM, [hidden email] (Tim Taplin) wrote:

>thanks for the pointers. Does the iterator function somehow sort
>elements on the way in?
>
>I've tested this with an array of pairs that is presorted into
>descending order using array->sort('false'). Then I use
>set->insertfrom(array->iterator) to create a unique set which then
>seems to be sorted in ascending order. I tried changing the
>array->sort command as well as using reverseiterator. both returned
>the same set sorted by the pair->first item in ascending order.
>
>I can deal with this is I can rely on it but I wanted to make
>sure this is expected behavior.

The [Set] always maintains its elements in sorted order.  The
->Iterator tag  returns the elements in the order they are in
the array, but then the [Set] is sorting them internally.  I
would skip sorting the arrays and then re-sort the set if you
need to.

Incidentally, if you have two sorted arrays there is another way
to do this.  You can use the various "set" tags that [Array]
provides to combine two arrays which are sorted in the same
order.  Lasso has ->Union, ->Intersection, and ->Difference for
the [Array], [Set], and [List] types.

local('numberset') = array;
#numberset->insert(1='one');
#numberset->insert(3='three');

local('greekset') = array;
#greekset->insert(1='alpha');
#greekset->insert(2='beta');

#greekset->union(#numberset);
==> array: (pair: (1)=(alpha)), (pair: (2)=(beta)), (pair: (3)=(three))

There are a lot of ways to work with data like this.

[fletcher]

--
Fletcher Sandbeck                         [hidden email]
LassoSoft, LLC                          http://www.lassosoft.com


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Tim Taplin
As long as i can rely on the set being in a known order, that works.  
I couldn't find in the reference guide any indication that set  
maintained a sort order. Is this supposed to be common knowledge? I  
have not used the set type in other languages so I dont know.

If I use a reverse iterator will a set provide me the data in reverse  
order or will it override and force the items to come out in its own  
order?

Thanks for all the help.

Tim

On Aug 28, 2008, at 6:31 PM, Fletcher Sandbeck wrote:

> On 8/28/08 at 6:07 PM, [hidden email] (Tim Taplin) wrote:
>
>> thanks for the pointers. Does the iterator function somehow sort
>> elements on the way in?
>>
>> I've tested this with an array of pairs that is presorted into
>> descending order using array->sort('false'). Then I use
>> set->insertfrom(array->iterator) to create a unique set which then
>> seems to be sorted in ascending order. I tried changing the
>> array->sort command as well as using reverseiterator. both returned
>> the same set sorted by the pair->first item in ascending order.
>>
>> I can deal with this is I can rely on it but I wanted to make sure  
>> this is expected behavior.
>
> The [Set] always maintains its elements in sorted order.  The -
> >Iterator tag  returns the elements in the order they are in the  
> array, but then the [Set] is sorting them internally.  I would skip  
> sorting the arrays and then re-sort the set if you need to.
>
> Incidentally, if you have two sorted arrays there is another way to  
> do this.  You can use the various "set" tags that [Array] provides  
> to combine two arrays which are sorted in the same order.  Lasso  
> has ->Union, ->Intersection, and ->Difference for the [Array],  
> [Set], and [List] types.
>
> local('numberset') = array;
> #numberset->insert(1='one');
> #numberset->insert(3='three');
>
> local('greekset') = array;
> #greekset->insert(1='alpha');
> #greekset->insert(2='beta');
>
> #greekset->union(#numberset);
> ==> array: (pair: (1)=(alpha)), (pair: (2)=(beta)), (pair: (3)=
> (three))
>
> There are a lot of ways to work with data like this.
>
> [fletcher]
>
> --
> Fletcher Sandbeck                         [hidden email]
> LassoSoft, LLC                          http://www.lassosoft.com
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Fletcher Sandbeck-3
On 8/28/08 at 7:01 PM, [hidden email] (Tim Taplin) wrote:

>As long as i can rely on the set being in a known order, that works. I
>couldn't find in the reference guide any indication that set
>maintained a sort order. Is this supposed to be common knowledge? I
>have not used the set type in other languages so I dont know.

The Language Guide does a better job breaking down the
differences between the types than the reference does.  The
Language Guide provides more background than the reference so
its often good to check it out as well.  Chapter 30: Arrays,
Maps, and Compound Data Types starts with a discussion of the
differences between Lasso's built-in compound data types and
when to choose one over the other.

>If I use a reverse iterator will a set provide me the data in
>reverse order or will it override and force the items to come
>out in its own order?

A reverse iterator will give you the items in reverse order.  
But, note that the use of iterators is a little different than
how the [Iterate] ... [/Iterate] tags work.

[fletcher]

--
Fletcher Sandbeck                         [hidden email]
LassoSoft, LLC                          http://www.lassosoft.com


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Array types with unique funtion

Bil Corry-3
Fletcher Sandbeck wrote on 8/28/2008 8:52 PM:
> The Language Guide does a better job breaking down the differences
> between the types than the reference does.  The Language Guide provides
> more background than the reference so its often good to check it out as
> well.  Chapter 30: Arrays, Maps, and Compound Data Types starts with a
> discussion of the differences between Lasso's built-in compound data
> types and when to choose one over the other.

It's online now :)

<http://docs.lassosoft.com/Lasso 8.5/003 Language Guide/005 Types/030 Arrays, Maps, and Compound Data Types/>


- Bil


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/