Re: [qooxdoo-devel] Array Searching Question

2012-01-04 Thread John Spackman
It's a little hard to debug on Firefox but it's just a function.  AIUI
it's quicker to push strings into an array and then join them, e.g.

var lcTxt=[];
for (i=0; i0)
   lcTxt.push("+");
 lcTxt.push("mRecord.get('");
 lcTxt.push(tmSearch.key[i]);
 lcTxt.push("')");
}
var Search = new Function(lcTxt.join(""));



On 04/01/2012 15:06, "Simon White"  wrote:

>Hi
>
>Yes I thought about building a AVL binary tree and attaching it to the
>store but I am not sure I need to as most of the data will be sorted on
>the server as part of an SQL statement so I only needed a method to
>lookup keys from a Data Dictionary where some of the widget properties
>are stored so the application can be customized by the client.
>
>I am interested to know if my method of creating the Search() function
>using the "new Function" syntax is the best way to accomplish a
>generalized evaluation technique.
>
>Simon
>
>
>On 04/01/2012 1:34 AM, John Spackman wrote:
>> Hi,
>>
>> If you've only got laTable as a flat array then a bisect search like
>>that
>> is about as good as it gets; if you're going to do a lot of lookups for
>> particular sets of keys you could consider building an index, e.g.
>>
>>  var lmIndex = {};
>>  for (var i = 0; i<  laTable.length; i++)
>>  lmIndex[Search(laTable[i])] = laTable[i];
>>
>>  var match = lmIndex[tmSearch.key];
>>
>>
>> You'd have to cache lmIndex for each set of keys and rebuild the index
>>if
>> the model changes.
>>
>> John
>>
>> On 04/01/2012 03:47, "Simon White"
>>wrote:
>>
>>> Hi
>>>
>>> I would appreciate feedback on the following search function. I would
>>> like to know if there are more efficient ways of accomplishing my goal
>>> of finding items in a store the quickest way possible.  It will be used
>>> on ordered JSON stores as follows:
>>>
>>> myStore.dcSeek({key: ["TABLE","ATYPE","NAME"],value:
>>> "VMMASTER.DBFFCARD"});
>>>
>>> The store in this case is order by three fields TABLE, ATYPE and NAME
>>> and I want to find the item whose TABLE == "VMMASTER.DBF" and ATYPE
>>> =="F" and NAME == "CARD"
>>>
>>> I tested it on a store with 2410 items and it finds the correct value
>>>in
>>> 10 tries and found a match at laTable[2336].
>>>
>>> dcSeek : function(tmSearch) {
>>> // get the model's data array
>>>  var laTable = this.getModel().get(this.getTable()).toArray();
>>>  var lcTxt = "";
>>>  var lcPlus = "";
>>>
>>> // build the text for the search function body
>>>
>>>  for (i=0; i>> lcTxt = lcTxt+lcPlus+"mRecord.get('"+tmSearch.key[i]+"')"
>>> lcPlus="+"
>>>  }
>>>
>>> // create a search function to retrieve the required array items
>>>
>>>  var Search = new Function("mRecord","return "+lcTxt)
>>>  var lnMin = 0;
>>>  var lnMax = laTable.length;
>>>  var lcKey = "";
>>>  while (lnMin<= lnMax)
>>>  {
>>>  lnMid = parseInt((lnMin+lnMax)/2);
>>>  this.mRecord = laTable[lnMid];
>>>  lcKey = Search(this.mRecord).toUpperCase();
>>>  if (lcKey>  tmSearch.value){
>>>  lnMax = lnMid -1;
>>>  } else if (lcKey<  tmSearch.value){
>>>  lnMin = lnMid +1;
>>>  } else {
>>>  return true;
>>>  }
>>>  }
>>>  this.mRecord = null;
>>>  return false
>>> }
>>>
>>>
>>>
>>>
>>> On 03/01/2012 3:27 PM, Simon White wrote:
 Hi

 This maybe more of a javascript question than QooxDoo and is due to my
 as yet inadequate knowledge of the inner workings of Javascript.

 I have an array in the form of:

 Menu = [{id: "TEST1",color: "blue",name: "myBlue"},
{id: "TEST36",color: "grey",name: "myGrey"},
{id: "TEST2",color: "red",name: "myRed"},
{id: "TEST34",color: "grey",name: "anotherGrey"}]

 In my case the array has more than 1000 elements and I want to find
the
 item containing the color == "grey" and the name =="myGrey".  Is
there a
 means to use the indexOf method or do I need to just create my own
 function for searching?

 I was trying to use a builtin methods assuming it would be faster than
 my custom code.

 Thanks
 Simon



 
---
--
 -
 Write once. Port to many.
 Get the SDK and tools to simplify cross-platform app development.
Create
 new or port existing apps to sell to consumers worldwide. Explore the
 Intel AppUpSM program developer opportunity.
appdeveloper.intel.com/join
 http://p.sf.net/sfu/intel-appdev
>>>
>>>
>>>
>>> 
>>>
>>>--
>>> 
>>> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a
>>>complex
>>> infrastructure or vast IT resources to deliver seamless, secure access
>>>to
>>> virtual desktops. With this all-in-one solution, easily deploy virtual
>>> desktops for less than the cost of PCs and s

Re: [qooxdoo-devel] Array Searching Question

2012-01-04 Thread Simon White
Hi

Yes I thought about building a AVL binary tree and attaching it to the 
store but I am not sure I need to as most of the data will be sorted on 
the server as part of an SQL statement so I only needed a method to 
lookup keys from a Data Dictionary where some of the widget properties 
are stored so the application can be customized by the client.

I am interested to know if my method of creating the Search() function 
using the "new Function" syntax is the best way to accomplish a 
generalized evaluation technique.

Simon


On 04/01/2012 1:34 AM, John Spackman wrote:
> Hi,
>
> If you've only got laTable as a flat array then a bisect search like that
> is about as good as it gets; if you're going to do a lot of lookups for
> particular sets of keys you could consider building an index, e.g.
>
>   var lmIndex = {};
>   for (var i = 0; i<  laTable.length; i++)
>   lmIndex[Search(laTable[i])] = laTable[i];
>
>   var match = lmIndex[tmSearch.key];
>
>
> You'd have to cache lmIndex for each set of keys and rebuild the index if
> the model changes.
>
> John
>
> On 04/01/2012 03:47, "Simon White"  wrote:
>
>> Hi
>>
>> I would appreciate feedback on the following search function. I would
>> like to know if there are more efficient ways of accomplishing my goal
>> of finding items in a store the quickest way possible.  It will be used
>> on ordered JSON stores as follows:
>>
>> myStore.dcSeek({key: ["TABLE","ATYPE","NAME"],value:
>> "VMMASTER.DBFFCARD"});
>>
>> The store in this case is order by three fields TABLE, ATYPE and NAME
>> and I want to find the item whose TABLE == "VMMASTER.DBF" and ATYPE
>> =="F" and NAME == "CARD"
>>
>> I tested it on a store with 2410 items and it finds the correct value in
>> 10 tries and found a match at laTable[2336].
>>
>> dcSeek : function(tmSearch) {
>> // get the model's data array
>>  var laTable = this.getModel().get(this.getTable()).toArray();
>>  var lcTxt = "";
>>  var lcPlus = "";
>>
>> // build the text for the search function body
>>
>>  for (i=0; i> lcTxt = lcTxt+lcPlus+"mRecord.get('"+tmSearch.key[i]+"')"
>> lcPlus="+"
>>  }
>>
>> // create a search function to retrieve the required array items
>>
>>  var Search = new Function("mRecord","return "+lcTxt)
>>  var lnMin = 0;
>>  var lnMax = laTable.length;
>>  var lcKey = "";
>>  while (lnMin<= lnMax)
>>  {
>>  lnMid = parseInt((lnMin+lnMax)/2);
>>  this.mRecord = laTable[lnMid];
>>  lcKey = Search(this.mRecord).toUpperCase();
>>  if (lcKey>  tmSearch.value){
>>  lnMax = lnMid -1;
>>  } else if (lcKey<  tmSearch.value){
>>  lnMin = lnMid +1;
>>  } else {
>>  return true;
>>  }
>>  }
>>  this.mRecord = null;
>>  return false
>> }
>>
>>
>>
>>
>> On 03/01/2012 3:27 PM, Simon White wrote:
>>> Hi
>>>
>>> This maybe more of a javascript question than QooxDoo and is due to my
>>> as yet inadequate knowledge of the inner workings of Javascript.
>>>
>>> I have an array in the form of:
>>>
>>> Menu = [{id: "TEST1",color: "blue",name: "myBlue"},
>>> {id: "TEST36",color: "grey",name: "myGrey"},
>>> {id: "TEST2",color: "red",name: "myRed"},
>>> {id: "TEST34",color: "grey",name: "anotherGrey"}]
>>>
>>> In my case the array has more than 1000 elements and I want to find the
>>> item containing the color == "grey" and the name =="myGrey".  Is there a
>>> means to use the indexOf method or do I need to just create my own
>>> function for searching?
>>>
>>> I was trying to use a builtin methods assuming it would be faster than
>>> my custom code.
>>>
>>> Thanks
>>> Simon
>>>
>>>
>>>
>>> -
>>> -
>>> Write once. Port to many.
>>> Get the SDK and tools to simplify cross-platform app development. Create
>>> new or port existing apps to sell to consumers worldwide. Explore the
>>> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
>>> http://p.sf.net/sfu/intel-appdev
>>
>>
>>
>> --
>> 
>> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
>> infrastructure or vast IT resources to deliver seamless, secure access to
>> virtual desktops. With this all-in-one solution, easily deploy virtual
>> desktops for less than the cost of PCs and save 60% on VDI infrastructure
>> costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
>> ___
>> qooxdoo-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
>
>
> --
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
> infrastructure or vast IT resources to deliver seamless, secure access to
> virtual deskt

Re: [qooxdoo-devel] Array Searching Question

2012-01-03 Thread John Spackman
Hi,

If you've only got laTable as a flat array then a bisect search like that
is about as good as it gets; if you're going to do a lot of lookups for
particular sets of keys you could consider building an index, e.g.

var lmIndex = {};
for (var i = 0; i < laTable.length; i++)
lmIndex[Search(laTable[i])] = laTable[i];

var match = lmIndex[tmSearch.key];


You'd have to cache lmIndex for each set of keys and rebuild the index if
the model changes.

John

On 04/01/2012 03:47, "Simon White"  wrote:

>Hi
>
>I would appreciate feedback on the following search function. I would
>like to know if there are more efficient ways of accomplishing my goal
>of finding items in a store the quickest way possible.  It will be used
>on ordered JSON stores as follows:
>
>myStore.dcSeek({key: ["TABLE","ATYPE","NAME"],value:
>"VMMASTER.DBFFCARD"});
>
>The store in this case is order by three fields TABLE, ATYPE and NAME
>and I want to find the item whose TABLE == "VMMASTER.DBF" and ATYPE
>=="F" and NAME == "CARD"
>
>I tested it on a store with 2410 items and it finds the correct value in
>10 tries and found a match at laTable[2336].
>
>dcSeek : function(tmSearch) {
>// get the model's data array
> var laTable = this.getModel().get(this.getTable()).toArray();
> var lcTxt = "";
> var lcPlus = "";
>
>// build the text for the search function body
>
> for (i=0; ilcTxt = lcTxt+lcPlus+"mRecord.get('"+tmSearch.key[i]+"')"
>lcPlus="+"
> }
>
>// create a search function to retrieve the required array items
>
> var Search = new Function("mRecord","return "+lcTxt)
> var lnMin = 0;
> var lnMax = laTable.length;
> var lcKey = "";
> while (lnMin <= lnMax)
> {
> lnMid = parseInt((lnMin+lnMax)/2);
> this.mRecord = laTable[lnMid];
> lcKey = Search(this.mRecord).toUpperCase();
> if (lcKey > tmSearch.value){
> lnMax = lnMid -1;
> } else if (lcKey < tmSearch.value){
> lnMin = lnMid +1;
> } else {
> return true;
> }
> }
> this.mRecord = null;
> return false
>}
>
>
>
>
>On 03/01/2012 3:27 PM, Simon White wrote:
>> Hi
>>
>> This maybe more of a javascript question than QooxDoo and is due to my
>> as yet inadequate knowledge of the inner workings of Javascript.
>>
>> I have an array in the form of:
>>
>> Menu = [{id: "TEST1",color: "blue",name: "myBlue"},
>>  {id: "TEST36",color: "grey",name: "myGrey"},
>>  {id: "TEST2",color: "red",name: "myRed"},
>>  {id: "TEST34",color: "grey",name: "anotherGrey"}]
>>
>> In my case the array has more than 1000 elements and I want to find the
>> item containing the color == "grey" and the name =="myGrey".  Is there a
>> means to use the indexOf method or do I need to just create my own
>> function for searching?
>>
>> I was trying to use a builtin methods assuming it would be faster than
>> my custom code.
>>
>> Thanks
>> Simon
>>
>>
>> 
>>-
>>-
>> Write once. Port to many.
>> Get the SDK and tools to simplify cross-platform app development. Create
>> new or port existing apps to sell to consumers worldwide. Explore the
>> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
>> http://p.sf.net/sfu/intel-appdev
>
>
>
>--
>
>Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
>infrastructure or vast IT resources to deliver seamless, secure access to
>virtual desktops. With this all-in-one solution, easily deploy virtual
>desktops for less than the cost of PCs and save 60% on VDI infrastructure
>costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
>___
>qooxdoo-devel mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel




--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


Re: [qooxdoo-devel] Array Searching Question

2012-01-03 Thread Simon White
Hi

I would appreciate feedback on the following search function. I would 
like to know if there are more efficient ways of accomplishing my goal 
of finding items in a store the quickest way possible.  It will be used 
on ordered JSON stores as follows:

myStore.dcSeek({key: ["TABLE","ATYPE","NAME"],value: "VMMASTER.DBFFCARD"});

The store in this case is order by three fields TABLE, ATYPE and NAME 
and I want to find the item whose TABLE == "VMMASTER.DBF" and ATYPE 
=="F" and NAME == "CARD"

I tested it on a store with 2410 items and it finds the correct value in 
10 tries and found a match at laTable[2336].

dcSeek : function(tmSearch) {
// get the model's data array
 var laTable = this.getModel().get(this.getTable()).toArray();
 var lcTxt = "";
 var lcPlus = "";

// build the text for the search function body

 for (i=0; i tmSearch.value){
 lnMax = lnMid -1;
 } else if (lcKey < tmSearch.value){
 lnMin = lnMid +1;
 } else {
 return true;
 }
 }
 this.mRecord = null;
 return false
}




On 03/01/2012 3:27 PM, Simon White wrote:
> Hi
>
> This maybe more of a javascript question than QooxDoo and is due to my
> as yet inadequate knowledge of the inner workings of Javascript.
>
> I have an array in the form of:
>
> Menu = [{id: "TEST1",color: "blue",name: "myBlue"},
>   {id: "TEST36",color: "grey",name: "myGrey"},
>   {id: "TEST2",color: "red",name: "myRed"},
>   {id: "TEST34",color: "grey",name: "anotherGrey"}]
>
> In my case the array has more than 1000 elements and I want to find the
> item containing the color == "grey" and the name =="myGrey".  Is there a
> means to use the indexOf method or do I need to just create my own
> function for searching?
>
> I was trying to use a builtin methods assuming it would be faster than
> my custom code.
>
> Thanks
> Simon
>
>
> --
> Write once. Port to many.
> Get the SDK and tools to simplify cross-platform app development. Create
> new or port existing apps to sell to consumers worldwide. Explore the
> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
> http://p.sf.net/sfu/intel-appdev



--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


[qooxdoo-devel] Array Searching Question

2012-01-03 Thread Simon White
Hi

This maybe more of a javascript question than QooxDoo and is due to my 
as yet inadequate knowledge of the inner workings of Javascript.

I have an array in the form of:

Menu = [{id: "TEST1",color: "blue",name: "myBlue"},
{id: "TEST36",color: "grey",name: "myGrey"},
{id: "TEST2",color: "red",name: "myRed"},
{id: "TEST34",color: "grey",name: "anotherGrey"}]

In my case the array has more than 1000 elements and I want to find the 
item containing the color == "grey" and the name =="myGrey".  Is there a 
means to use the indexOf method or do I need to just create my own 
function for searching?

I was trying to use a builtin methods assuming it would be faster than 
my custom code.

Thanks
Simon


--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel