Heh, I guess that won't work. :) <div><br></div><div><br></div><div>I'll try the bubblesort.. </div><div><br></div><div>Thanks,</div><div>Brett</div><div><br><br><div class="gmail_quote">On Fri, May 14, 2010 at 9:28 AM, Anca Vamanu <span dir="ltr"><<a href="mailto:anca@opensips.org">anca@opensips.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Brett Nemeroff wrote:<br>
> Bogdan,<br>
> Thanks for this.. I'll give it a shot. This should be pretty fast, right?<br>
><br>
> I didn't understand in the set_select_weight function what sets the<br>
> weight of each element. ?<br>
</div>Hi Brett,<br>
<br>
Weight refers in fact to the value stored, so if you have a list of<br>
values, the greatest value has the most chances to be selected, but it<br>
is not 100% sure it will be selected.<br>
<br>
Regards,<br>
<br>
--<br>
Anca Vamanu<br>
<a href="http://www.voice-system.ro" target="_blank">www.voice-system.ro</a><br>
<div class="im"><br>
<br>
<br>
<br>
<br>
><br>
> Thanks!<br>
> -Brett<br>
><br>
><br>
> On Fri, May 14, 2010 at 3:38 AM, Bogdan-Andrei Iancu<br>
</div><div class="im">> <<a href="mailto:bogdan@voice-system.ro">bogdan@voice-system.ro</a> <mailto:<a href="mailto:bogdan@voice-system.ro">bogdan@voice-system.ro</a>>> wrote:<br>
><br>
> Hi Brett,<br>
><br>
> There is no such builtin functionality - what we have is for<br>
> weight-base<br>
> selection (see<br>
> <a href="http://www.opensips.org/html/docs/modules/s1.6.x/cfgutils.html#id228612" target="_blank">http://www.opensips.org/html/docs/modules/s1.6.x/cfgutils.html#id228612</a><br>
</div>> <<a href="http://www.opensips.org/html/docs/modules/1.6.x/cfgutils.html#id228612" target="_blank">http://www.opensips.org/html/docs/modules/1.6.x/cfgutils.html#id228612</a>>).<br>
<div><div></div><div class="h5">><br>
> What I can suggest (as a fast solution) is to implement a bubble-sort<br>
> algh in the script:<br>
><br>
> $var(changed) = 1;<br>
> while ( $var(changed)==1 ) {<br>
> $var(i) = 0;<br>
> $var(changed) = 0;<br>
> while ( $(avp(s:price)[$var(i)+1])!=NULL ) {<br>
> if ( $(avp(s:price)[$var(i)]) ><br>
> $(avp(s:price)[$var(i)+1]) )<br>
> $var(tmp) = $(avp(s:price)[$var(i)+1]);<br>
> $(avp(s:price)[$var(i)+1]) =<br>
> $(avp(s:price)[$var(i)]) ;<br>
> $(avp(s:price)[$var(i)]) = $var(tmp);<br>
> $var(changed) = 1;<br>
> }<br>
> $var(i) = $var(i) + 1;<br>
> }<br>
> }<br>
><br>
> haven't tried that so far :P<br>
><br>
> Regards,<br>
> Bogdan<br>
><br>
> Brett Nemeroff wrote:<br>
> > Hello All,<br>
> > I'm looking to numerically sort data.. Basically what I need is an<br>
> > array with numerical data values to be sorted (yes, for pricing)<br>
> ><br>
> ><br>
> > $avp(s:price)[0]=0.0125<br>
> > $avp(s:price)[1]=0.0138<br>
> > $avp(s:price)[2]=0.0128<br>
> > $avp(s:price)[3]=0.0112<br>
> > $avp(s:price)[4]=0.0005<br>
> > $avp(s:price)[5]=0.0149<br>
> ><br>
> ><br>
> > And I'd like to....<br>
> ><br>
> > <magic><br>
> > $avp(s:price_sorted) = avp_sort("$avp(s:price)");<br>
> > </magic><br>
> ><br>
> > Is that possible with.. anything? It doesn't need to be an AVP..<br>
> just<br>
> > looking for any sortable data structure.<br>
> ><br>
> > Thanks,<br>
> > Brett<br>
> ><br>
> ><br>
> ><br>
> ------------------------------------------------------------------------<br>
> ><br>
> > _______________________________________________<br>
> > Users mailing list<br>
</div></div>> > <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a> <mailto:<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>><br>
<div class="im">> > <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
> ><br>
><br>
><br>
> --<br>
> Bogdan-Andrei Iancu<br>
</div>> <a href="http://www.voice-system.ro" target="_blank">www.voice-system.ro</a> <<a href="http://www.voice-system.ro" target="_blank">http://www.voice-system.ro</a>><br>
><br>
><br>
> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a> <mailto:<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>><br>
<div><div></div><div class="h5">> <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
><br>
><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
> <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
><br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
</div></div></blockquote></div><br></div>