You appear to be trying to implement a linear search? If `line[0]` is a
string you could just use an Object which I believe is implemented as some
kind of hash table in v8.

var table = Object.create(null);
var item = table[line[0]];
if (item && item[0] === line[0]) {
  table[line[0]] = line;
}

If `line[0]` isn't scalar please look in to something like a "binary
search" or "trie" if you can.

On Fri, Jun 15, 2012 at 9:20 PM, vitoa <[email protected]> wrote:

> Hi, I me working one a algorithm that is not performing well :/
> First I receive an serial data an event to hanle it
> sp.on('data',function)... this data is stored in array line.
> First field of data contain a unique id and than some values, sometimes
> receive dat from same id and others from diferent id, and i need to put it
> in a table, refresh or add.
> I'm trying to find a record in table, and if it is not found i wish to
> append it to table. However if it find it I want to update it.
>
>
>       z=table.length;
>       while(tempo<z) {
>
>
>         if(table[tempo][0] == line[0] )
>          {
>         table[tempo]=line;
>         console.log('table[tempo] :' + table[tempo] + 'line '+ line);
>         tempo=0;
>         break;
>         }
>
>         if(table[tempo][0] != line[0] ){
>
>                 tempo=tempo+1;
>                         if(tempo==z){
>                                 console.log('xxx :' + tempo + 'table
> length:'+ z);
>                                 tempo=0;
>                                 break;
>                         }
>         }
>
> }
>
> I dont know why onl can record on id, than all new id are stored in last
> id position and not added to table.
>
> An ideia?
> Regards,
> Vitor
>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to