[OpenSIPS-Users] Sorting Lists of Data
Brett Nemeroff
brett at nemeroff.com
Fri May 14 16:50:44 CEST 2010
Heh, I guess that won't work. :)
I'll try the bubblesort..
Thanks,
Brett
On Fri, May 14, 2010 at 9:28 AM, Anca Vamanu <anca at opensips.org> wrote:
> Brett Nemeroff wrote:
> > Bogdan,
> > Thanks for this.. I'll give it a shot. This should be pretty fast, right?
> >
> > I didn't understand in the set_select_weight function what sets the
> > weight of each element. ?
> Hi Brett,
>
> Weight refers in fact to the value stored, so if you have a list of
> values, the greatest value has the most chances to be selected, but it
> is not 100% sure it will be selected.
>
> Regards,
>
> --
> Anca Vamanu
> www.voice-system.ro
>
>
>
>
>
> >
> > Thanks!
> > -Brett
> >
> >
> > On Fri, May 14, 2010 at 3:38 AM, Bogdan-Andrei Iancu
> > <bogdan at voice-system.ro <mailto:bogdan at voice-system.ro>> wrote:
> >
> > Hi Brett,
> >
> > There is no such builtin functionality - what we have is for
> > weight-base
> > selection (see
> >
> http://www.opensips.org/html/docs/modules/s1.6.x/cfgutils.html#id228612
> > <
> http://www.opensips.org/html/docs/modules/1.6.x/cfgutils.html#id228612>).
> >
> > What I can suggest (as a fast solution) is to implement a bubble-sort
> > algh in the script:
> >
> > $var(changed) = 1;
> > while ( $var(changed)==1 ) {
> > $var(i) = 0;
> > $var(changed) = 0;
> > while ( $(avp(s:price)[$var(i)+1])!=NULL ) {
> > if ( $(avp(s:price)[$var(i)]) >
> > $(avp(s:price)[$var(i)+1]) )
> > $var(tmp) = $(avp(s:price)[$var(i)+1]);
> > $(avp(s:price)[$var(i)+1]) =
> > $(avp(s:price)[$var(i)]) ;
> > $(avp(s:price)[$var(i)]) = $var(tmp);
> > $var(changed) = 1;
> > }
> > $var(i) = $var(i) + 1;
> > }
> > }
> >
> > haven't tried that so far :P
> >
> > Regards,
> > Bogdan
> >
> > Brett Nemeroff wrote:
> > > Hello All,
> > > I'm looking to numerically sort data.. Basically what I need is an
> > > array with numerical data values to be sorted (yes, for pricing)
> > >
> > >
> > > $avp(s:price)[0]=0.0125
> > > $avp(s:price)[1]=0.0138
> > > $avp(s:price)[2]=0.0128
> > > $avp(s:price)[3]=0.0112
> > > $avp(s:price)[4]=0.0005
> > > $avp(s:price)[5]=0.0149
> > >
> > >
> > > And I'd like to....
> > >
> > > <magic>
> > > $avp(s:price_sorted) = avp_sort("$avp(s:price)");
> > > </magic>
> > >
> > > Is that possible with.. anything? It doesn't need to be an AVP..
> > just
> > > looking for any sortable data structure.
> > >
> > > Thanks,
> > > Brett
> > >
> > >
> > >
> >
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Users mailing list
> > > Users at lists.opensips.org <mailto:Users at lists.opensips.org>
> > > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
> > >
> >
> >
> > --
> > Bogdan-Andrei Iancu
> > www.voice-system.ro <http://www.voice-system.ro>
> >
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.opensips.org <mailto:Users at lists.opensips.org>
> > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.opensips.org
> > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opensips.org/pipermail/users/attachments/20100514/22d06512/attachment.htm
More information about the Users
mailing list