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.
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
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?
>
> 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
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