java - Offset and limit for a set -
i have 2 ordered sets of integers - sortedset<integer>, call them set1 , set2. need find union of sets , return subset offset 10 limit 10. mean?
set1: 1,2,5,6,7,8,11,21,23,543,1002 set2: 11,12,15,16,17,8,111,121,123,1543,11002 union: 1,2,5,6,7,8,11,21,23,543,1002,12,15,16,17,111,121,123,1543,11002 union offset 10 limit 10: 1002,12,15,16,17,111,121,123,1543,11002 note, cardinalities of 8 , 11 in union 1.
i'm looking algorithm allows me not load entire sets memory (because sets may quite large, not waste server's resources). there way that? maybe instant libraries commons or guava can of?
upd: myself don't use java 8, solution using interesting.
the algorithm quite simple.
create empty hash create empty array set waste counter 0 iterate sets (2 or more) iterate set values if value not in hash insert value hash increase waste counter if waste counter > offset (10) insert value array if array length == limit (10) done - return array
Comments
Post a Comment