No, because in your new code, you do not take care of connection
drops/failures. For example, suppose you have 5 notes trying to connect
simutanously (or in whatever order they are pleased to take), the node 0
comes first, then node 4, then node 1, then 2, then 3. With this scenario,
your code won't work.

Ha.

On Tue, Feb 12, 2013 at 11:10 AM, Antonio <[email protected]> wrote:

> Hi to all, and thanks to Ha and Eric for her  their responses.
> do you think this code is a good? is it a more easy to understand ?
>
> .....
>   int newLength=0;
> if(nodes.length==0){
>
>          newLength = nodeId + 1;
>     Node newNodes[] = new Node[newLength];
>         System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
>         nodes = newNodes;
>     }
> // if arrives new node
>
>     if (nodeId >= nodes.length) {
>         int newLength = nodes.length * 2;
>     Node newNodes[] = new Node[newLength];
>         System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
>         nodes = newNodes;
>     }
> ......
> ....
> best regads
> Antonio
>   ------------------------------
> *Da:* Eric Decker <[email protected]>
> *A:* Dang Thi Hai Ha <[email protected]>
> *Cc:* Antonio <[email protected]>; tinyos forum <
> [email protected]>
> *Inviato:* Martedì 12 Febbraio 2013 10:48
> *Oggetto:* Re: [Tinyos-help] example Oscilloscope
>
>
>
> On Tue, Feb 12, 2013 at 1:21 AM, Dang Thi Hai Ha <[email protected]>wrote:
>
> Hi,
>
> My answer is written inline below:
>
> ....
> /* Data received from mote nodeId containing NREADINGS samples from
>        messageId * NREADINGS onwards. Tell parent if this is a new node. */
>     void update(int nodeId, int messageId, int readings[]) {
>     if (nodeId >= nodes.length) {
>         int newLength = nodes.length * 2;
>
>
> This is to avoid changing the nodes.length everytime a new node arrives.
>
>
>
>         if (nodeId >= newLength) {
>             newLength = nodeId + 1;
>         }
>
> This is to treat the case when node.length = 0.
>
>
> That seems like a rather convoluted (unclear) way of checking for 0.   Why
> don't you simply check for node.length == 0?
>
>
>
>
>
>
> now because i have this:  int newLength = nodes.length * 2; because it's
> multiplies for two?
> because i have this new controll
>      if (nodeId >= newLength) {
>             newLength = nodeId + 1;
>         }
>
> if i change this code in this i think don't have a real effect, i think
> true?
> if (nodeId +1 >= nodes.length) {
>         int newLength = nodes.length * 4;
>         if (nodeId >= newLength) {
>             newLength = nodeId + 1;
>         }
>
>
> Please explain your purpose for this change? What do you want?
>
> Cheers,
>
> Ha.
>
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
>
>
>
> --
> Eric B. Decker
> Senior (over 50 :-) Researcher
>
>
>
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to