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.key.length; 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