Commit d42cf15a authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
	  
# 9780596510046
	  
[![9780596510046](https://resources.oreilly.com/uploads/system/group/avatar/3/tarsier_hi_elbows.png)](https://www.safaribooksonline.com/)
	  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
	  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
	  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
	  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
	  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

examples.tar.gz

0 → 100755
+11.8 KiB

File added.

No diff preview for this file type.

+23 −0
Changes for examples/Bray/big-hash.rb: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
class BigHash

  def initialize(file)
    @hash = {}
    lines = 0
    File.open(file).each_line do |line|
      s = line.split
      article = s[2].intern
      if @hash[s[0]]
        @hash[s[0]] << [ s[1], article ]
      else
        @hash[s[0]] = [ s[1], article ]
      end
      lines += 1
      STDERR.puts "Line: #{lines}" if (lines % 100000) == 0
    end
  end

  def find(key)
    @hash[key]
  end

end
+43 −0
Changes for examples/Bray/binary-search.rb: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
class BinarySearch

  attr_reader :keys, :values
  def initialize(file, size = 0)
    last = ''
    @keys = Array.new(size)
    @values = Array.new(size)
    lines = 0
    hosts = -1
    File.open(file).each_line do |line|
      s = line.split
      article = s[2].intern
      if s[0] != last
        hosts += 1
        @keys[hosts] = s[0]
        @values[hosts] = []
        last = s[0]
      end
      @values[hosts] << [ s[1], article ]
      lines += 1
      STDERR.puts "Line: #{lines}" if (lines % 100000) == 0
    end
  end

  def find(target)
    low = -1
    high = @keys.size
    while (high - low) > 1 do
      probe = (high + low) / 2
      if (@keys[probe] > target)
        high = probe
      else
        low = probe
      end
    end
    if low == -1 || @keys[low] != target
      return nil
    else
      return @values[low]
    end
  end

end
+8 −0
Changes for examples/Bray/count-fetches.rb: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
counts = {}
counts.default = 0

ARGF.each_line do |line|
  if line =~ %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }
    counts[$1] += 1
  end
end
Loading