Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

blt vector insert ordered

0 views
Skip to first unread message

end...@gmail.com

unread,
Apr 25, 2006, 6:27:30 AM4/25/06
to
I would like to insert elements in order in a blt vector avoiding the
use of the sort command, as I have to keep ordered more than two
vectors.

For example, to insert in the position 0 (without removing the value in
index 0 as with the "index" command), it is possible to use an
auxiliary vector, doing:
$vector dup $auxVector
$vector set $valueToInsert
$vector append $auxVector

To insert in the middle of the vector it could be performed in a
similar way, but I do not think this is an intelligent way of doing
this operation.

Is there any way more suitable to do this? something like the "linsert"
command for TCL lists but for BLT vectors?

Thanks.

Uwe Klein

unread,
Apr 25, 2006, 7:03:12 AM4/25/06
to
no?
i may have missunderstood your question but you can sort vector sets
with blt:

vector x
vector y
vector z
vector a ...

x sort y z a .... ;# keeping indices in x and y ( and all others ) paired

<from man blt_vector>
The sort operation sorts the vector. If any additional vectors are
specified, they are rearranged in the same order as the vector. For
example, you could use it to sort data points represented by x and y
vectors.

# Sort the data points
x sort y

The vector x is sorted while the components of y are rearranged so that
the original x,y coordinate pairs are retained.
<end>

if you want a special ordering append data to all vectors and then sort
to a vector that holds your desired ordering.
i.e.
vector idx
idx set {1 2 3 4 8 9 10 5 6 7}
idx sort y z a ..
uwe

end...@gmail.com

unread,
Apr 25, 2006, 7:34:08 AM4/25/06
to
Thanks, maybe I have not explained well before.

Sure I can sort them, but the issue is that I want to avoid sorting the
vectors by keeping them in order. I am managing very large vectors and
sorting them involves too much cost in performance.

My idea is to keep the vectors ordered with an operation of the kind:
"vector insert index value",
avoiding the needed to sort them, just like linsert for lists.

I do not know if I can make this operation easily with BLT.

The command "index" of blt vector allows to change the value in such
index, but not to insert a new value in that position.

Any ideas?

Uwe Klein

unread,
Apr 25, 2006, 8:02:03 AM4/25/06
to
end...@gmail.com wrote:
> Thanks, maybe I have not explained well before.
>
> Sure I can sort them, but the issue is that I want to avoid sorting the
> vectors by keeping them in order. I am managing very large vectors and
> sorting them involves too much cost in performance.
Does it? ( I've done it on sets 20++ vectors and 100000++ elements and
it wasn't realy that bad)
how many vector and elements in a vector are you aiming for?
how often will you add, how often will you need the sorted vectors?

>
> My idea is to keep the vectors ordered with an operation of the kind:
> "vector insert index value",
> avoiding the needed to sort them, just like linsert for lists.
>
> I do not know if I can make this operation easily with BLT.
>
> The command "index" of blt vector allows to change the value in such
> index, but not to insert a new value in that position.

some way ( will take more time than just sorting):
# extract values as list
set values [ $vec set ]
# do an linsert ...
set values [ linsert $values ... ]
# put them back :
$vec set $values

# but this dumps the advantages "vector" has.

i would probably stay with sorting
but do the sorting only on demand.

uwe

end...@gmail.com

unread,
Apr 25, 2006, 8:56:10 AM4/25/06
to
Thanks!

I will try sorting, which was also the first idea I had. It is simpler
and faster than the other procedure I have tried.

I use some sets of 4 vectors of 100000 samples. It appends a sample
each second within the vectors, but the user can request the values
faster and in both directions, forward and backward.

I was trying to improve performance and I had found two main issues: a
kind of autoscale while zooming, which is the blocking one, and the
event of storing the values each second within the vectors.

For that reason, if I could easily insert the sample at the position 0
I would avoid sorting the vectors each time a sample is added.

So, I thought that the kind of command "vector insert index value"
would be very useful and would also use all vector advantages.

Thank you very much.

Uwe Klein

unread,
Apr 25, 2006, 9:49:39 AM4/25/06
to
end...@gmail.com wrote:
> Thanks!
>
> I will try sorting, which was also the first idea I had. It is simpler
> and faster than the other procedure I have tried.
>
> I use some sets of 4 vectors of 100000 samples. It appends a sample
> each second within the vectors, but the user can request the values
> faster and in both directions, forward and backward.
you have very nimble users?

>
> I was trying to improve performance and I had found two main issues: a
> kind of autoscale while zooming, which is the blocking one, and the
> event of storing the values each second within the vectors.
What do you use for zooming ? blt_ZommStack ?

>
> For that reason, if I could easily insert the sample at the position 0
> I would avoid sorting the vectors each time a sample is added.
>
> So, I thought that the kind of command "vector insert index value"
> would be very useful and would also use all vector advantages.
there are some more i would like:
drop first element for every append, keep length constant

uwe

0 new messages