<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,6 +3,20 @@
 import sys, re
 from bisect import bisect
 
+def binary_search(a, x, lo=0, hi=None):
+    if hi is None:
+        hi = len(a)
+    while lo &lt; hi:
+        mid = (lo + hi) // 2
+        midval = a[mid]
+        if midval &lt; x:
+            lo = mid + 1
+        elif midval &gt; x: 
+            hi = mid
+        else:
+            return mid
+    return -1
+
 if __name__ == &quot;__main__&quot;:
 
 	segments = open(sys.argv[1])
@@ -11,7 +25,7 @@ if __name__ == &quot;__main__&quot;:
 	offsets = []
 	sections = []
 	offset = size = 0
-	
+
 	# read in sections
 	
 	for line in segments:
@@ -56,6 +70,9 @@ if __name__ == &quot;__main__&quot;:
 	
 	# read in page-ins
 	
+	print offsets
+	print sections
+	
 	for line in pageins:
 		
 		# vnode_pagein: XUL, offset: 20254720, size: 24576
@@ -64,11 +81,15 @@ if __name__ == &quot;__main__&quot;:
 		
 		if m:			
 			start, size = map(int, m.group(1, 2))
-			ix = bisect(offsets, start)
-			if ix &gt;= len(sections):
-				print offsets
-				print line
-				print &quot;start: %d, ix: %d&quot; % (start, ix)
+			#ix = bisect(offsets, start)
+			
+			#if offsets[ix] &gt; start:
+			#	ix -= 1
+
+			ix = binary_search(offsets, start)
+		
+			print &quot;binary_search(offsets, %d) = %d&quot; % (start, ix)
+			
 			sect = sections[ix]
 			pages = size / 4096
 			print &quot;%s, %s = %d pages&quot; % (sect[0], sect[1], pages)</diff>
      <filename>mmap/access-pattern.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>107a72dee485c676c5bb208cf925e4e7691fb2c6</id>
    </parent>
  </parents>
  <author>
    <name>wagerlabs</name>
    <email>joelr1@gmail.com</email>
  </author>
  <url>http://github.com/wagerlabs/firefox-startup/commit/9207becba11fc308f266c11e460c16757d0280de</url>
  <id>9207becba11fc308f266c11e460c16757d0280de</id>
  <committed-date>2009-11-05T13:24:34-08:00</committed-date>
  <authored-date>2009-11-05T13:24:34-08:00</authored-date>
  <message>now with binary search</message>
  <tree>b0f64b7f23670b85fcdbf5cce5a1e432ebfa28c5</tree>
  <committer>
    <name>wagerlabs</name>
    <email>joelr1@gmail.com</email>
  </committer>
</commit>
