Using a loop back node to build array okay instead of shift registers?
Attached is a sample of how I want to accomplish appending to multiple arrays and would like an opinion wether it is acceptable or not. I didn't want to use 12 shift registers wired from the 6 possible case structures mainly because of esthetic reasons. Each case will be called in turn during program execution only once. So case 0 builds it's array then later case 1 and so on. It seems to work but frankly manipulating arrays in LV confuses me a bit. I cannot test in the actual program since the hardware the complete program controls is not yet installed. Your input as to the wisdom of doing this or proposing a better solution (maybe one that actually works) is appreciated
Mike
Attachments:
sample2.vi 33 KB
You never have more than one element in each array since you initialize the shift register with every call of the VI.
Use "built array" instead of "insert into array", it's cleaner. However, since you only kep one elements, maybe you can jist place the scalar value inside a shift register. Make sure the default value is NaN so you know when it contains valid data.
All you probably need is an array of fixed size (12) and replace appropriate elements as need arises.
What you probably want is an action engine. See http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=240328#M240328
LabVIEW Champion . Do more with less code and in less time .
Similar Messages
-
Array of Clusters Counters / Shift registers
Hello All,
In my Array of Clusters, I'm having trouble controlling my MISS PACKET indicator. Each time a packet is missed , the MISS PACKET indicator increments by 1. My problems is, that the same number of miss packets is showing up in the MISS PACKET indicator in each array index if a packet is missed. Ex. So if index[0] has missed 30 packets, whenever index[1] misses a packet it will display 31 and not 1. I'm using a shift register to keep a count of the number of missed packets. I believe the shift register is the issue because the previous value is store whenever a packet is missed.
Any help would be appreciate !
Thanks
Attachments:
Final-Demo - 3.vi 52 KBThe first time i tried using a shift register I had the initalization done outside of the while loop and still got the same results
Attachments:
Final-Demo - 3.vi 47 KB -
Hi guys,
I am testing out array. How do I create a 1D array of x-y using for loop?Nextal wrote:
I am testing out array. How do I create a 1D array of x-y using for loop?
OK, first of all you did not say what the array should contain. If you want an array that has one array element for each iteration of the while loop, you need to first think a bit harder. Your outer loop has no wait, thus it will spin millions of times per second and you will run out of memory soon, no matter how much memory you have. How many times should the while loop iterate? If you know the number before the program starts, you would use a FOR loop and autoindex at the loop boundary.
If you want to use a whiile loop, you need a mechanism to keep the array size reasonable. For small final arrays, you can just build the array in a shift register if you need it updated as it happens. If you only need the array after the loop stops, you can autoindex at the right loop boundary.
In any case, you should take a step back and decide what you really want. Currently the specifications are very vague and unreasonable.
LabVIEW Champion . Do more with less code and in less time . -
How to avoid Build Array function inside a For (while) Loop?
Hi there,
I have a simple question about how to avoid using Build Array function inside the loop. Now I want to remove the Build Array funtion inside the loop to improve the performance (To get better memory management). Any idea how to do that?
Thanks a lot!
Warmest regards,
ChongIt's been my experience that using the auto-indexing to build an array
on a For loop is just as good as initializing and replacing elements.
The For loop knows before it runs how many iterations it has to run and
can allocate the array ahead of time.
You're better off initializing and replacing when using a While loop
because it does not know how many iterations it will run and can't
pre-allocate the array ahead of time.
Ed
Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences. -
I stuck with a problem that I am using FOR loop for generating repeating nodes.
Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
can anybody suggest me a way to handle this error....
FOR i IN 1..pl_phone_tab.Count
LOOP
SELECT xmlelement("Phone"
,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
INTO p_phone_xml
FROM dual; END LOOP;
SELECT xmlelement("PhoneInfo"
,xmlconcat(p_phone_xml))
INTO p_phone_info_xml
FROM dual;
here I am getting only one node but there has to be two nodes for PHONE nodeNot that I'm encouraging you but here are two standalone examples explaining how to do what you want :
1) Loop through the input collection and append each node to its target container :
SQL> declare
2
3 type t_emp_tab is table of scott.emp%rowtype;
4
5 emp_tab t_emp_tab;
6 emp_info_xml xmltype;
7 emp_xml xmltype;
8
9 begin
10
11 -- filling emp_tab with data
12 select e.*
13 bulk collect into emp_tab
14 from scott.emp e
15 where e.deptno = 10;
16
17 emp_info_xml := xmltype('<EmpInfo/>');
18
19 -- looping through emp collection and appending to EmpInfo element
20 for i in 1 .. emp_tab.count loop
21 select appendchildxml(
22 emp_info_xml
23 , '/*'
24 , xmlelement("Emp"
25 , xmlattributes(emp_tab(i).empno as "id")
26 , xmlforest(
27 emp_tab(i).ename as "Name"
28 , emp_tab(i).job as "Job"
29 )
30 )
31 )
32 into emp_info_xml
33 from dual;
34 end loop;
35
36 dbms_output.put_line(emp_info_xml.getclobval(1,2));
37
38 end;
39 /
<EmpInfo>
<Emp id="7782">
<Name>CLARK</Name>
<Job>MANAGER</Job>
</Emp>
<Emp id="7839">
<Name>KING</Name>
<Job>PRESIDENT</Job>
</Emp>
<Emp id="7934">
<Name>MILLER</Name>
<Job>CLERK</Job>
</Emp>
</EmpInfo>
PL/SQL procedure successfully completed
2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
SQL> declare
2
3 type t_emp_tab is table of scott.emp%rowtype;
4
5 emp_tab t_emp_tab;
6 emp_info_xml xmltype;
7 emp_xml_tab xmlsequencetype := xmlsequencetype();
8
9 begin
10
11 -- filling emp_tab with data
12 select e.*
13 bulk collect into emp_tab
14 from scott.emp e
15 where e.deptno = 10;
16
17 -- looping through emp collection and appending to the collection of Emp nodes
18 for i in 1 .. emp_tab.count loop
19
20 emp_xml_tab.extend;
21
22 select xmlelement("Emp"
23 , xmlattributes(emp_tab(i).empno as "id")
24 , xmlforest(
25 emp_tab(i).ename as "Name"
26 , emp_tab(i).job as "Job"
27 )
28 )
29 into emp_xml_tab(i)
30 from dual;
31
32 end loop;
33
34 select xmlelement("EmpInfo", xmlagg(t.column_value))
35 into emp_info_xml
36 from table(emp_xml_tab) t ;
37
38 dbms_output.put_line(emp_info_xml.getclobval(1,2));
39
40 end;
41 /
<EmpInfo>
<Emp id="7782">
<Name>CLARK</Name>
<Job>MANAGER</Job>
</Emp>
<Emp id="7839">
<Name>KING</Name>
<Job>PRESIDENT</Job>
</Emp>
<Emp id="7934">
<Name>MILLER</Name>
<Job>CLERK</Job>
</Emp>
</EmpInfo>
PL/SQL procedure successfully completed
Both solutions give the same output.
Test them both and see which one fits better into your scenario. -
IPhone: Using embedded QT movies that either Loop or Loop Back and Forth
Hi to everyone,
I'm working on a very simple iPhone app:
it has several buttons that launch different QuickTime movies embedded in the application, that will either Loop or Loop Back and Forth.
The desired looping behaviour is already set within QuickTime itself (those settings are available in QuickTime's View menu).
So far it doesn't seem to work, as the iPhone's SDK doesn't seem to recognize these QuickTime settings of Loop or Loop Back and Forth.
I've been trying to find advanced documentation on the matter, with no luck.
Does anyone knows if it's possible to create an iPhone application that has embedded QuickTime movies that either Loop or Loop Back and Forth?
If it is possible to do so, can you please post some code (or links) explaining how to proceed?
If the feature is not currently supported, does anyone knows if it will eventually be supported by Apple (maybe in a future SDK revision)?
While I don't know the entire context the SDK engineering team has to contend with, it seems to me it should be rather simple for Apple's iPhone SDK to simply accept the settings already put in place inside a QuickTime movie.
Many thanks in advance for any feedback on this!Well, my programmers have come back to me and the news is not good.
The QTMovieLoopsAttribute is not supported in the SDK's QT Kit.
I'll now call it SDK's *QuickTime Kit Lite*, if you don't mind.
*QuickTime Kit Lite*, the key audio/video toolbox available for development of applications on the iPhone through the SDK, provides a single option:
a Play / Stop button.
The only other thing available (I think) is the option to hide the play/stop controller. That's it.
Apparently, there are several unofficial, private frameworks that give access to lower-level QuickTime functions and that may provide a way to actually loop videos, but chances are that an app using these unofficial frameworks would get rejected by Apple upon submission for the store.
I'm still waiting for more info and the final word from my programmers, but from the looks of it, this is going to be a show-stopper shortcoming of QT Kit Lite, as far as my project is concerned.
I'm probably going to have to fold my project and wait (hope) for an eventual upgrade to the SDK's QT Kit.
By the way, does anyone knows if there is a way to communicate with Apple and request new features for inclusion in future revisions of the SDK?
Upgrading the QuickTime Kit librairies to include the video Loop and Loop Back and Forth Attributes would be my first (and only) request.
many thanks to all! -
Building Tree hierarchy Using nested loops and class cl_gui_column_tree
Hello gurus,
I want to create a tree report using custom container and class cl_gui_column_tree. I have read and understood the standard demo report which SAP has provided i.e. SAPCOLUMN_TREE_CONTROL_DEMO. But in this report all the levels nodes are created as constants and hardcoded. I want to create hierarchy using nested loops. For this i took one example of a hierarchy of VBAK-VBELN->VBAP-POSNR Like One sales order has many line items and each line item can have number of line items in billing plan.
I have done some coding for it.
FORM build_tree USING node_table TYPE treev_ntab
item_table TYPE zitem_table. " i created the zitem_table table type of mtreeitm in SE11.
DATA: node TYPE treev_node,
item TYPE mtreeitm.
node-node_key = root.
CLEAR node-relatkey.
CLEAR node-relatship.
node-hidden = ' '.
node-disabled = ' '.
CLEAR node-n_image.
CLEAR node-exp_image.
node-isfolder = 'X'.
node-expander = 'X'.
APPEND node TO node_table.
item-node_key = root.
item-item_name = colm1.
item-class = cl_gui_column_tree=>item_class_text.
item-text = 'Root'.
APPEND item TO item_table.
item-node_key = root.
item-item_name = colm2.
item-class = cl_gui_column_tree=>item_class_text.
item-text = 'Amount'.
APPEND item TO item_table.
LOOP AT it_vbeln INTO wa_vbeln.
node-node_key = wa_vbeln-vbeln.
node-relatkey = root.
node-relatship = cl_gui_column_tree=>relat_last_child.
node-hidden = ' '.
node-disabled = ' '.
CLEAR node-n_image.
CLEAR node-exp_image.
node-isfolder = 'X'.
node-expander = 'X'.
APPEND node TO node_table.
item-node_key = wa_vbeln-vbeln.
item-item_name = colm1.
item-class = cl_gui_column_tree=>item_class_text.
item-text = wa_vbeln-vbeln.
APPEND item TO item_table.
item-node_key = wa_vbeln-vbeln.
item-item_name = colm2.
item-class = cl_gui_column_tree=>item_class_text.
item-text = wa_vbeln-netwr.
APPEND item TO item_table.
LOOP AT it_posnr INTO wa_posnr.
node-node_key = wa_posnr-posnr.
node-relatkey = wa_vbeln-vbeln.
node-relatship = cl_gui_column_tree=>relat_last_child.
node-hidden = ' '.
node-disabled = ' '.
CLEAR node-n_image.
CLEAR node-exp_image.
node-isfolder = ' '.
node-expander = ' '.
APPEND node TO node_table.
item-node_key = wa_posnr-posnr.
item-item_name = colm1.
item-class = cl_gui_column_tree=>item_class_text.
item-text = wa_posnr-posnr.
APPEND item TO item_table.
item-node_key = wa_posnr-posnr.
item-item_name = colm2.
item-class = cl_gui_column_tree=>item_class_text.
item-text = wa_posnr-netpr.
APPEND item TO item_table.
ENDLOOP.
ENDLOOP.
ENDFORM.
Now this program compiles fine and runs till there is only one level. That is root->vbeln. But when i add one more loop of it_posnr it gives me runtime error of message type 'X'. The problem i found was uniqueness of item-item_name as all the sales order have posnr = 0010. What could be done? I tried giving item_name unique hierarchy level using counters just like stufe field in prps eg. 10.10.10, 10.10.20,10.20.10,10.20.20,20.10.10 etc.. etc.. but still i am getting runtime error when i add one more hierarchy using nested loop. Plz guide.
Edited by: Yayati6260 on Jul 14, 2011 7:25 AMHello all,
Thanks the issue is solved. The node key was not getting a unique identification as nodekey. I resolved the issue by generating unique identification for each level. Thanks all,
Regards
Yayati Ekbote -
A suggestion : use "loop array list" instead of ArrayList / LinkedList
ArrayList is good at:
get / set by index : O(1)
appending : O(log(n))
remove last : O(1)
and very bad at:
add middle : O(n)
remove from middle : O(n)
LinkedList is good at:
fast remove from middle, if your iteraror already goes there : O(1)
convenient methods : addFirst, addLast, removeFirst, removeLast : O(1)
and very bad at :
get / set by index : O(n)
here I want to make a suggestion : use "loop array list" instead of the ArrayList and LinkedList.
a "loop array list" is based on array, just like ArrayList. But it has 2 member-variables : the start position, and the real size. the start position can be anywhere within array.length. an element of index "i" is stored in array[ start + i ], and when (start + i > array.length), loop to the beginning of the array; when (start + i < 0), loop to the end of the array.
this "loop array list" has all the good sides:
get / set by index : O(1)
add first / last : O(log(n))
remove first / last : O(log(n))
add / remove from middle : O(n)
(note : because we shrink the backup-array when the real size is too small, add / remove operation take O(log(n)) now.)
the only problem is : add / remove from middle. let's take a look at it.
1. the LinkedList does NOT really add/remove from middle in O(1), you has to locate the element, which is O(n).
2. O(n) is acceptable, O(n^2) is not acceptable. try this : keep removing first element from an very big ArrayList ( size>10^6 ) until it's empty.
the fact is, any list can perform batch-remove / batch-add operation in O(n) instead of O(n^2). it's easy : allocate a new list, iterate the original list, copy the element into the new list if condition is satisfied.
so, instead of "remove from middle", what we need is a new methods : removeAllByCondition( Condition condition ), and now the batch-remove operation can be done in O(n)
here is an implementation of mine. I've tested it on my computer( 512mem + 2G cpu, win2k + jdk1.5 ), it's amazing, just a little slower then ArrayList when add last, and a liitle slower then LinkedList when batch-remove. in all other cases, it's far more better then those 2 kinds of List.
// source code : List2
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
public final class List2<T> extends AbstractList<T> {
private static int initialArrayLength = 4;
private T[] array;
private int start;
private int size;
private void init( T[] newArray, int start_a, int size_a ) {
array = newArray;
start = start_a;
size = size_a;
@SuppressWarnings("unchecked")
private void init() {
init( (T[]) new Object[ initialArrayLength ], 0, 0 );
public List2() {
init();
@SuppressWarnings("unchecked")
public List2( Collection<? extends T> collection ) {
init(
collection.toArray( (T[]) new Object[ collection.size() * 11 / 10 + 1 ] ),
0,
collection.size()
private List2( T[] array_a, int start_a, int size_a ) {
init( array_a, start_a, size_a );
@SuppressWarnings("unchecked")
public static <TT> List2<TT> createV( TT... elements ) {
TT[] array = (TT[]) new Object[ elements.length * 11 / 10 + 1 ];
System.arraycopy( elements, 0, array, 0, elements.length );
return new List2<TT>( array, 0, elements.length );
public static List2<Double> create( double... elements ) {
Double[] array = new Double[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array[i] = elements;
return new List2<Double>( array, 0, elements.length );
public static List2<Integer> create( int... elements ) {
Integer[] array2 = new Integer[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array2[i] = elements[i];
return new List2<Integer>( array2, 0, elements.length );
public static List2<Character> create( char... elements ) {
Character[] array2 = new Character[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array2[i] = elements[i];
return new List2<Character>( array2, 0, elements.length );
public static List2<Character> create( String s ) {
return create( s.toCharArray() );
public List2<T> clone() {
return new List2<T>( this );
// basic
public int size() {
return size;
private int index( int index ) {
int i = start + index;
if( i >= array.length )
i -= array.length;
return i;
public T get( int d ) {
if( d < 0 || d >= size )
throw new IndexOutOfBoundsException();
if( size == 0 )
throw new NoSuchElementException();
return array[ index( d ) ];
public T set( int index, T element ) {
if( index < 0 || index >= size )
throw new IndexOutOfBoundsException();
int i = index( index );
T oldElement = array[i];
array[i] = element;
return oldElement;
@SuppressWarnings("unchecked")
private void copyAndSetToNewArray( int newArrayLength ) {
T[] newArray = (T[]) new Object[ newArrayLength ];
for( int i=0; i<size; i++ )
newArray[i] = array[ index( i ) ];
init( newArray, 0, size );
public void addFirst( T element ) {
if( size == array.length )
copyAndSetToNewArray( size * 3 / 2 + 1 );
int i = index( array.length - 1 );
array[ i ] = element;
start = i;
size++;
public void addLast( T element ) {
if( size == array.length )
copyAndSetToNewArray( size * 3 / 2 + 1 );
array[ index( size ) ] = element;
size++;
public T removeFirst() {
if( size == 0 )
throw new NoSuchElementException();
T oldElement = array[ start ];
array[ start ] = null;
start = index( 1 );
size--;
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return oldElement;
public T removeLast() {
if( size == 0 )
throw new NoSuchElementException();
int i = index( size - 1 );
T oldElement = array[i];
array[i] = null;
size--;
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return oldElement;
@SuppressWarnings("unchecked")
public int removeAll( ListCondition<T> condition ) {
T[] newArray = (T[]) new Object[ array.length ];
int iNew = 0;
for( int i=0; i < size; i++ ) {
T element = get( i );
if( ! condition.isConditionSatisfied( this, i, element ) )
newArray[ iNew++ ] = element;
int oldSize = size;
init( newArray, 0, iNew );
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return size - oldSize;
// aux
public boolean equals(Object obj) {
if( obj == this )
return true;
if( obj instanceof List2 ) {
List2 that = (List2) obj;
if( this.size != that.size )
return false;
for( int i=0; i < size; i++ )
if( ! Tools.equals( this.array[ this.index(i) ], that.array[ that.index(i) ] ) )
return false;
return true;
if( obj instanceof List ) {
List that = (List) obj;
if( this.size != that.size() )
return false;
Iterator thatIter = that.iterator();
for( int i=0; i < size; i++ )
if( ! Tools.equals( this.array[ this.index(i) ], thatIter.next() ) )
return false;
return true;
return true;
public int hashCode() {
int hashCode = 1;
for( int i=0; i < size; i++ ) {
T element = array[ index( i ) ];
hashCode = 31*hashCode + ( element==null ? 0 : element.hashCode() );
return hashCode;
public boolean isEmpty() {
return size == 0;
public T getFirst() {
return get( 0 );
public T getLast() {
return get( size() - 1 );
public T getRandom() {
return get( (int) (Math.random() * size) );
public int indexOf( Object element ) {
for( int i=0; i < size; i++ )
if( Tools.equals( array[ index( i ) ], element ) )
return i;
return -1;
public int lastIndexOf( Object element ) {
for( int i=size-1; i >= 0; i-- )
if( Tools.equals( array[ index( i ) ], element ) )
return i;
return -1;
public boolean contains( Object element ) {
return indexOf( element ) != -1;
public boolean add( T element ) {
addLast( element );
return true;
@Deprecated
public void add( int index, T element ) {
throw new UnsupportedOperationException();
public T remove() {
return removeFirst();
@Deprecated
public boolean remove( Object element ) {
throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
@Deprecated
public T remove( int index ) {
throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
public void clear() {
init();
public Object[] toArray() {
Object[] result = new Object[ size ];
for( int i=0; i < size; i++ )
result[i] = array[ index( i ) ];
return result;
@SuppressWarnings("unchecked")
public <TT> TT[] toArray( TT[] a ) {
if( a.length < size )
a = (TT[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size );
for( int i=0; i < size; i++ )
a[i] = (TT) array[ index( i ) ];
if( a.length > size )
a[size] = null;
return a;
@SuppressWarnings("unchecked")
public void sort() {
Object[] a = toArray();
Arrays.sort( a );
for( int i=0; i < size; i++ )
array[ i ] = (T) a[ i ];
start = 0;
@SuppressWarnings("unchecked")
public void sortDesc() {
Object[] a = toArray();
Arrays.sort( a );
for( int i=0, j=size-1; i < size; i++, j-- )
array[ i ] = (T) a[ j ];
start = 0;
@SuppressWarnings("unchecked")
public void sort( Comparator<T> comparator ) {
T[] a = (T[]) toArray();
Arrays.sort( a, comparator );
for( int i=0; i < size; i++ )
array[ i ] = a[ i ];
start = 0;
@SuppressWarnings("unchecked")
public void sortDesc( Comparator<T> comparator ) {
T[] a = (T[]) toArray();
Arrays.sort( a, comparator );
for( int i=0, j=size-1; i < size; i++, j-- )
array[ i ] = a[ j ];
start = 0;
public String toString( String delimiter ) {
return toString( "", delimiter, "", size() );
public String toString( String prefix, String delimiter, String suffix, int max ) {
StringBuffer stringBuffer = new StringBuffer( prefix );
int dest = Math.min( max, size );
for( int i=0; i < dest; i++ ) {
stringBuffer.append( get(i) );
if( i < dest - 1 )
stringBuffer.append( delimiter );
if( size > max )
stringBuffer.append( "...(" ).append( size() - max ).append( " more)" );
stringBuffer.append( suffix );
return stringBuffer.toString();
// batch operation
public boolean containsAll( Collection<?> that ) {
Set<Object> thisSet = new HashSet<Object>( this );
for( Object element : that )
if( ! thisSet.contains( element ) )
return false;
return true;
@SuppressWarnings("unchecked")
public List2<T> subList( int fromIndex, int toIndex ) {
if( fromIndex < 0 || toIndex > size || toIndex < fromIndex )
throw new IndexOutOfBoundsException();
int newSize = toIndex - fromIndex;
T[] newArray = (T[]) new Object[ newSize * 11 / 10 + 1 ];
for( int i=fromIndex, iNew=0; i < toIndex; i++, iNew++ )
newArray[ iNew ] = array[ index( i ) ];
return new List2<T>( newArray, 0, newSize );
public void addV( T... that ) {
for( T element : that )
addLast( element );
public boolean addAll( Collection<? extends T> that ) {
for( T element : that )
addLast( element );
return ! that.isEmpty();
@Deprecated
public boolean addAll( int index, Collection<? extends T> c ) {
throw new UnsupportedOperationException();
public void removeRest( T element ) {
int position = lastIndexOf( element );
if( position == -1 )
return;
while( ! Tools.equals( element, removeLast() ) );
public void removeAllEquals( final T element ) {
removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T currentElement) {
return currentElement.equals( element );
public void removeAllBetween( final T from, final T to ) {
removeAll( new ListCondition<T>() {
@SuppressWarnings("unchecked")
public boolean isConditionSatisfied(List2 list, int index, T element) {
if( from != null && ((Comparable) from).compareTo( element ) > 0 )
return false;
if( to != null && ((Comparable) to).compareTo( element ) <= 0 )
return false;
return true;
public boolean retainAll( Collection<?> that ) {
final Set<Object> thatSet = new HashSet<Object>( that );
int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
return ! thatSet.contains( element );
return removeCount > 0;
public boolean removeAll( Collection<?> that ) {
final Set<Object> thatSet = new HashSet<Object>( that );
int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
return thatSet.contains( element );
return removeCount > 0;
// unit test
private static int maxTestCount = 1000 * 1000;
public static void unitTest() throws Exception {
// thest thoese methods for one time
Tools.ensureEquals( new List2(), new ArrayList() );
Tools.ensureNotEquals( List2.create( "abcde" ), new ArrayList() );
Tools.ensureNotEquals( List2.create( "abcde" ), List2.create( "abcdef" ) );
final List<Double> list1 = new ArrayList<Double>();
final List2<Double> list2 = new List2<Double>();
Runnable[] tasks = new Runnable[] {
// test those methods that do NOT change the list
new Runnable() { public void run() {
Tools.ensureEquals( new List2<Double>( list1 ), list1 );
Tools.ensureEquals( List2.createV( list1.toArray() ), list1 );
Tools.ensureEquals( List2.createV( list1.toArray( new Double[0] ) ), list1 );
double[] doubles = new double[ list1.size() ];
int i = 0;
for( double d : list1 )
doubles[i++] = d;
Tools.ensureEquals( List2.create( doubles ), list1 );
Tools.ensure( list1.isEmpty() == list2.isEmpty() );
Arrays.equals( list1.toArray(), list2.toArray() );
Tools.ensureEquals( list1, list2.clone() );
Double notExistElement = -2.0;
Tools.ensure( list1.indexOf( notExistElement ) == -1 );
Tools.ensure( list1.lastIndexOf( notExistElement ) == -1 );
Tools.ensure( list1.contains( notExistElement ) == false );
Tools.ensureEquals( list1.toString(), list2.toString() );
Tools.ensureEquals( list1.toString(), list2.toString() );
Tools.ensureEquals( list1.hashCode(), list2.hashCode() );
if( list1.isEmpty() )
return;
Tools.ensure( list1.get(0).equals( list2.getFirst() ) );
Tools.ensure( list1.get(list1.size()-1).equals( list2.getLast() ) );
Double existRandomElement = list2.getRandom();
Tools.ensure( list1.contains( existRandomElement ) );
Tools.ensure( list2.contains( existRandomElement ) );
Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
int from = (int) (Math.random() * list1.size());
int to = (int) (Math.random() * (list1.size()+1));
if( from > to ) {
int t = from;
from = to;
to = t;
Tools.ensureEquals( list1.subList( from, to ), list2.subList( from, to ) );
// test those methods that change the list
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = (int) (Math.random() * list1.size());
double d = Math.random();
list1.set( i, d );
list2.set( i, d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = (int) (Math.random() * list1.size());
Tools.ensure( list1.get( i ).equals( list2.get( i ) ) );
new Runnable() { public void run() {
double d = Math.random();
list1.add( 0, d );
list2.addFirst( d );
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.addLast( d );
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.addLast( d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove( 0 ).equals( list2.removeFirst() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove( list1.size() - 1 ).equals( list2.removeLast() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = 0;
for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); i++ ) {
iter.next();
if( i % 3 == 0 )
iter.remove();
list2.removeAll( new ListCondition<Double>() { public boolean isConditionSatisfied(List2 list, int index, Double element) {
return index % 3 == 0;
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.add( d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove(0).equals( list2.remove() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int r = (int) (Math.random() * list1.size());
Double element = list1.get( r );
int index = list1.lastIndexOf( element );
for( int i=list1.size()-1; i>=index; i-- )
list1.remove( i );
list2.removeRest( element );
new Runnable() { public void run() {
list2.removeRest( Math.random() - 2 );
new Runnable() { public void run() {
list1.clear();
list2.clear();
new Runnable() { public void run() {
Collections.sort( list1 );
list2.sort();
new Runnable() { public void run() {
Collections.sort( list1 );
Collections.reverse( list1 );
list2.sortDesc();
new Runnable() { public void run() {
Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
Collections.sort( list1, comparator );
list2.sort( comparator );
new Runnable() { public void run() {
Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
Collections.sort( list1, comparator );
Collections.reverse( list1 );
list2.sortDesc( comparator );
new Runnable() { public void run() {
Double notExistElement = -2.0;
list2.removeAllEquals( notExistElement );
Tools.ensureEquals( list1, list2 );
list2.removeAllBetween( 0.5, 0.6 );
for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); ) {
double d = iter.next();
if( d >= 0.5 && d < 0.6 )
iter.remove();
Tools.ensureEquals( list1, list2 );
System.out.print( "test List2 " );
for( int i=0; i < maxTestCount; i++ ) {
tasks[ (int) (Math.random() * tasks.length) ].run();
Tools.ensureEquals( list1, list2 );
if( i % (maxTestCount/10) == 0 )
System.out.print( "." );
System.out.println( " ok" );
// source code : ListCondition
public interface ListCondition<T> {
boolean isConditionSatisfied( List2 list, int index, T element );Hi,
I have the following statement:
private List list = new ArrayList();
why not use private ArrayList list = new
ArrayList()?
I know ArrayList implements List, so list has a wide
scope, right? What's the benefit?
Thanks,
JieBy using the interface you are not tied to a specific implementation.
Later, you may determine that using a LinkedList is more efficient to your specific code and then all you need to do is change the statement to:
private List list = new LinkedList();As long as you are not casting the list reference to ArrayList (or something along those lines) you would not need to change anything else. -
HT201250 Using Time Capsule for Backing Up a RAID Array
I am setting up an 8TB RAID 0 array at home. I am going to use 4 - 2TB FW drives. I already have an SSD in my 3.4 Ghz i7 iMac but am speed hungry and since I have the drives, I figure I would play a bit. I know it is vital to have solid back-up for this, but I am unsure of the best back-up solution. I am wondering if I can attach 3 - 3TB drives to my 1TB Time Capsule and use the combined 10TB in Time Machine to back it up? To date I have backed up each drive separately, but am realizing the folly of that and want to explore RAID 0 at the same time as explore a new back-up solution. Everything I read tells me I need a drive for backing up the RAID array that is at least as large as the combined total of the array. That doesn't make sense if the array is so large... I can't find anywhere if Time Machine supports spanning mulitple back-up drives.
According to the document linked below, you can, but it may not have the performance to back up that much data. Over Wi-Fi, forget it.
Uses for the USB port of Time Capsule, AirPort Extreme, AirPort Express -
When PC System timing hits 0000hrs Loops back to start and runs again using Loop function?
When PC System timing hits 0000hrs Loops back to start and runs again using Loop function?
It's all described in the help for it. Vista version:
Attachments:
Task Scheduler.png 61 KB -
Getting a FLV to loop back toward a specific frame using Netstream (as3)
To preface this my knowledge of AS3 is quite novice. As the thread titled reads, I'm trying to get an FLV to play through it's entireity and then loop back towards a specific frame and keep replaying from the point endlessly. After a lot of digging I found a video tutorial using AS3 that worked! Here's my situation now though, I cannot find the right code to insert to make the video loop back to the frame that I want. The FLV just stops and doesnt rewind at the end of the video. Here is my code so far:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
trace(meta.duration);
ns.client = meta;
video.attachNetStream(ns);
ns.play("All.flv");
Ultimately, the video needs to play all the way through only on the first load and then loop back to frame 319 and play toward the end and loop back again to frame 319 infinitely. I think I'm almost there, I just need some assistance with getting my code working appropriately. I done this before using "gotoAndPlay()" but the loop isnt seamless thus it yields a one second pause before looping back. I'm hoping using a Netstream function that this will be resolved. I would appreciate any help!Okay let me try and get this checked through you before I attempt to implement what you've recommend for a seamless loot at the aformentioned time in the previous post:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(Event.ENTER_FRAME,); <-----not too sure about the rest of the syntax here
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
function netStatusF(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetStream.Play.Stop":
ns.seek(10.6106);
break;
Hmmm, curious about where the"loop" and ns.time syntax should be placed. -
When I try to log on to click n ship it keeps looping back to sign in. It will not let me send package. Started with usps updated of site.
I had the same problem and found the solution here:
https://discussions.apple.com/thread/3189272 -
I want to link nine arrays whose dimension is 2*2 horizontally,but the function 'build array' (concatenated way) made them vertically.........help me please..........maybe this is too simple.........since I am only a students who learnd labview only few months..
Solved!
Go to Solution.A transpose operation only solves certain scenarios, but you don't give enough information on what you actually want.
For example, of you have 3 2x2 arrays:
a1 a2 b1 b2 c1 c2
a3 a4 b3 b4 c3 c4
What should the final vertical result be?
a1 a2
a3 a4
b1 b2
b3 b4
c1 c2
c3 c4
or
a1 a3
a2 a4
b1 b3
b2 b4
c1 c3
c2 c4
Or something else?
Please be much more specific. Maybe even attach a small VI containing typical default data.
LabVIEW Champion . Do more with less code and in less time . -
Using LV Class Property Nodes in In-place Element structure causes the code to halt
I have some code written in LV RT 2010 that uses property nodes from a LVOOP class that I created. I am using access the property node from inside an in-place element structure. When the code reaches the property node, LabVIEW stops running. (as if the abort button was pressed). I verified this behaviour using highlight execution. When I remove the in-place structure code runs fine.
Is this is know bug in LabVIEW? Is there a CAR to resolve this created for a future release?Bob,
I tried to reproduce the behavior you're seeing by recreating the Trigger and Trigger List classes, but I have not been able to reproduce it. Please take a look at my version of the project in the attached zip file. Take a look at Test.vi, and feel free to modify and repost it to show me how to make the problem occur. I would like to file a CAR to make sure we get the problem fixed, but I will need to be able to reliably reproduce it first.
On a similar note, you can get much better performance out of the Process Triggers VI by preallocating the list array, instead of using build array in a loop. Take a look at Process Triggers2.vi in my project. You can run Benchmark.vi to see the performance difference between the two different approaches.
Chris M
Attachments:
triggerlist test.zip 165 KB -
Replace build array with replace subset array
Currently I am using a build array function, but would like to replace it with a replace array subset, but I am new to labview and having a lot of trouble. I've attached a screen shot of the code I am struggling with. Does anyone have any ideas?
Attachments:
Build array code.JPG 29 KBFirst, I'm assuming this is inside some sort of loop. Second, I would recommend cleaning up the code a bit so the feedback node is not overhanging the edge of the case structure. It's unclear as to what is wired to what. Third, I would recommend using shift registers instead of the feedback node.
Fourth, and the main thing is that you are currently initializing a 64 element 1-D array and appending it to your array on every iteration with the build array.
If you want to use the replace array subset. Initialize the array to the size you want outside of the loop. Feed it into the left hand shift register. Replace each row (or column) with your new data. You will need to track the iterations, and possibly add special code to shift the array, or enlarge the array in the event you have more data come in then the original size of your array.
Maybe you are looking for
-
What is stander width in html web page?
Is there stander width for web pages? Sometimes I found who said it is should be 730px as max, is this right? If not then, how I should be chose a width of my page to clear and nice in difference browsers with difference resolution of monitor I wish
-
All songs are gone, still taking up space
Hi, just recently my iPod has been acting a bit weird and it has been having trouble connecting to my computer. I plugged it in last night and it failed to show up in iTunes or my Windows Explorer. I left it plugged in just in case it just had to tak
-
(Mac Mini mid-2011) Installing an SSD drive as a replacement of the HDD
Hey all, I just got myself a Crucial M500 240GB SSD drive for my mid-2011 Mac Mini. I intend to replace the standard hard drive with this one. Here are a couple of thigs that are still unclear to me : - what will happen when I first boot my Mini afte
-
Syncing dual boot data: SL and Mavericks?
Hello Happy New Year to Us All! I am wondering what to do to best keep user data between SL and Mavericks synced? I have an old Macbook Pro with Snow Leopard and I want to dual boot SL and Mavericks. My computer is an 8 gb RAM mid '09 15" Macbookk P
-
I have purchased Trend Micro Titanium Maximum Security and am now unable to install any plugins. I have had these plugins before and had no trouble with them but now they have disappeared. I tried closing the antivirus and added mozilla.org to the ex