Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Binary search to find max working graph size
import sys
import urllib
import urllib2
REPOSITORY = "http://localhost:8080/openrdf-sesame/repositories/test/statements"
head="""INSERT DATA {
GRAPH <http://one-graph-to-break-them-all> { """
tail=""" }
def graph_of_size(n):
middle = []
for j in range(n):
middle.append("<http://one-node> <http://sees> <http://%s>."%j)
return head + "\n".join(middle) + tail
def request_for_n(n):
values = {'update': graph_of_size(n)}
data = urllib.urlencode(values)
req = urllib2.Request(REPOSITORY, data)
response = urllib2.urlopen(req)
def binary_search(lower, upper):
while (lower < upper):
mid = (lower+upper)/2
print "Succeed, moving lower to", mid
lower = mid
except Exception as e:
print e, "Fail, moving upper to", mid
upper = mid-1
print "converged to", lower
return lower
upper = 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.