Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Testing for overlapping arrays in Ruby -


say have array of arrays in ruby,

[[100,300],   [400,500]] 

that i'm building adding successive lines of csv data.

what's best way, when adding new subarray, test if range covered 2 numbers in subarray covered previous subarrays?

in other words, each subarray comprises linear range (100-300 , 400-500) in example above. if want exception thrown if tried add [499,501], example, array because there overlap, how best test this?

since subarrays supposed represent ranges, might idea use array of ranges instead of array of array.

so array becomes [100..300, 400..500].

for 2 ranges, can define method checks whether 2 ranges overlap:

def overlap?(r1, r2)   r1.include?(r2.begin) || r2.include?(r1.begin) end 

now check whether range r overlaps range in array of ranges, need check whether overlap?(r, r2) true r2 in array of ranges:

def any_overlap?(r, ranges)   ranges.any? |r2|     overlap?(r, r2)   end end 

which can used this:

any_overlap?(499..501, [100..300, 400..500]) #=> true  any_overlap?(599..601, [100..300, 400..500]) #=> false 

here any_overlap? takes o(n) time. if use any_overlap? every time add range array, whole thing o(n**2).

however there's way want without checking each range:

you add ranges array without checking overlap. check whether range in array overlaps other. can efficiently in o(n log n) time sorting array on beginning of each range , testing whether 2 adjacent ranges overlap:

def any_overlap?(ranges)   ranges.sort_by(&:begin).each_cons(2).any? |r1,r2|     overlap?(r1, r2)   end end 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -