~nchohan/+junk/mytools

« back to all changes in this revision

Viewing changes to sample_apps/mapreduce/gen_input.rb

  • Committer: root
  • Date: 2010-11-03 07:43:57 UTC
  • Revision ID: root@appscale-image0-20101103074357-xea7ja3sor3x93oc
init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/ruby -w
 
2
# Programmer: Chris Bunch
 
3
# gen_input: Generates input in such a way that Map will be able to pick it
 
4
# up and compute EB
 
5
 
 
6
POWER = 10
 
7
N = 2 ** POWER
 
8
BUCKET_SIZE = 2 ** (POWER / 2)
 
9
 
 
10
file_system = "local"
 
11
 
 
12
vals = (1 .. N / BUCKET_SIZE).to_a
 
13
vals = vals.map { |i| i = BUCKET_SIZE * i }
 
14
 
 
15
output = ""
 
16
vals.each_index { |i|
 
17
  if i == 0
 
18
    start = 0
 
19
  else
 
20
    start = vals[i-1]
 
21
  end
 
22
  
 
23
  output << "#{start+1}\t#{vals[i]}\n"
 
24
}
 
25
 
 
26
if file_system == "local"
 
27
  File.open("input", "w+") { |file| file.write(output) }
 
28
else
 
29
 
 
30
end