actionscript 3 - Flex Filterfunction - Filter by Array of values -


How to filter an array with "value of the array" rather than a value (simple comparison), the code snippet below is single Now I was in the scenario to filter by value such that just filter the value [10,4,1,8] (some random value from the master collection). There is a better way to snippet the other code

Function Function Simple Comparison

  Personal Function Filters Filter Data (Items : Object): Boolean {if (item.price & lt; slider.value) true back; Second false return; }    

Filter by values ​​array

  Personal function filterFormatData (object: object, filter by: array = [10] , 4, 1,8]): Boolean {for (randomprice in filterBy) returned item item.price == randomprice; } [Edit]   

Apply filter

  testData.filterFunction = filterForTestData;   

[edit]

I have not mentioned that my data in a point filter is the custom data in the array are not the original datatype

I was saying that using an object as a lookup, it is to determine whether to use the property Use the hasOwnProperty for filter object is set to actually test my method with these two methods (NO Creating a fake set of data with a string of values ​​(100,000 of them) and variation between methods (between 130 to 160ms) in the context of run-time. I basically think three of them at the same time It's my complete code, so that you can roam and tell if I did something that invalidates my test but using this index makes me understand it set. To come back It is not as long as the object holds an object (not just a linear collection tree) with an ovenproperty (to get the list of all the properties and not to be repeated), as long as the property is more efficiently There is no mechanism to find. :

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Mx: application xmlns: mx = "http://www.adobe.com/ 2006/MxMM" layout = "vertical" height = "100%" width = "100%" xmlns: code = "http: // code. Google.com/p/flex-iframe/ "build end =" application 1_action end dler (event) "& gt; & Lt; Mx: script & gt; & Lt ;! [CDATA [Import Flash. Import mx.collections.ArrayCollection; Import mx.events.FlexEvent; / * Private Function FiltersFertestadata (item: object): Boolean {return filter by openproperty (item); } * / / * Personal Function FilterFormatData (Item: Object): Boolean {Return Filter by Indexoff (item)! = -1; } * / Private Function FiltersFertestadata (item: object): Boolean {for (different random providers in filter berries) Return items == Random value; return false; } [Bindable] Private WORLD DP: Arrayculation = New Arrayed (['1', '2', '3', '4', '5', '6', '7', '8']); Private var filterBy: object = {'10': true, '4': true, '1': true, '8': true}; // Private var filter By: Array = ['10', '4', '1', '8']; Protected Function Button 2_Clicker (Event: MouseEvent): Zero {// Todo Auto-Generated Method Stub Vers startTime: int = getTimer (); Trace (getTimer ()); Dp.filterFunction = filterForTestData; Dp.refresh (); Var end time: int = getTimer (); Trace ("Total Time:" + (End-Time-Time) .toString ()); } Secure Function Application 1_creationCompleteHandler (Event: FlexEvent): Zero {// Automatically generated method for TODO stub (var i: int = 0; i & lt; 100000; i ++) {dp.addItem (Math.For ( Mathematics. Randem) * 100) .toString ()); } TheList.dataProvider = DP; }] & Gt; & Lt; / Mx: script & gt; & Lt; Mx: list id = "the list" width = "100" /> & Lt; Mx: button click = "button2_click handler (event)" /> & Lt; / Mx: Applications & gt;   

I am going to try and think this through the perspective of a pure data and see if it can be a better time to run or if it is the nature of the problem which is necessary A certain number of investigations (asymptotic analysis)

Good question.

[edit] Well, after thinking through it, I believe that without using more complex data structure (and taking time to process the cost of building / reconstructing the data structure ... thinking of placing a balanced tree for searching) I am quite convinced that any method will have an equal or worse run time (which is a time of linear walking or worse) (N) tree compared to these methods Structure structure Yoga and you take more processing overhead to keep looking for the O (log n) running time-balanced tree (essentially rotating tax) for. If someone can invalidate this statement then I would be happy if you do so, but I believe that all this is true.



Comments