{"action":"created","comment":{"url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments/91811372","pull_request_review_id":12324933,"id":91811372,"diff_hunk":"@@ -0,0 +1,290 @@\n+package hosttree\n+\n+import (\n+\t\"crypto/rand\"\n+\t\"errors\"\n+\t\"sync\"\n+\n+\t\"github.com/NebulousLabs/Sia/modules\"\n+\t\"github.com/NebulousLabs/Sia/types\"\n+)\n+\n+var (\n+\t// ErrWeightTooHeavy is returned from a Fetch() call if a weight that exceeds\n+\t// the total weight of the tree is requested.\n+\tErrWeightTooHeavy = errors.New(\"requested a too-heavy weight\")\n+\n+\t// ErrNegativeWeight is returned from an Insert() call if an entry with a\n+\t// negative weight is added to the tree. Entries must always have a positive\n+\t// weight.\n+\tErrNegativeWeight = errors.New(\"cannot insert using a negative weight\")\n+\n+\t// ErrNilEntry is returned if a fetch call results in a nil tree entry. nodes\n+\t// should always have a non-nil entry, unless they have been Delete()ed.\n+\tErrNilEntry = errors.New(\"node has a nil entry\")\n+\n+\t// ErrHostExists is returned if an Insert is called with a public key that\n+\t// already exists in the tree.\n+\tErrHostExists = errors.New(\"host already exists in the tree\")\n+\n+\t// ErrNoSuchHost is returned if Remove is called with a public key that does\n+\t// not exist in the tree.\n+\tErrNoSuchHost = errors.New(\"no host with specified public key\")\n+)\n+\n+type (\n+\t// WeightFunc is a function used to weight a given HostDBEntry in the tree.\n+\tWeightFunc func(modules.HostDBEntry) types.Currency\n+\n+\t// HostTree is a data structure that contains a weighted tree of\n+\t// `HostEntries`, and provides methods for inserting, retreiving, and\n+\t// modifing entries.\n+\tHostTree struct {","path":"modules/renter/hostdb/hosttree/hosttree.go","position":42,"original_position":42,"commit_id":"940375cd3207ac0b0b8c7a9b63bcca47d3fd2e5b","original_commit_id":"940375cd3207ac0b0b8c7a9b63bcca47d3fd2e5b","user":{"login":"lukechampine","id":3344749,"avatar_url":"https://avatars.githubusercontent.com/u/3344749?v=3","gravatar_id":"","url":"https://api.github.com/users/lukechampine","html_url":"https://github.com/lukechampine","followers_url":"https://api.github.com/users/lukechampine/followers","following_url":"https://api.github.com/users/lukechampine/following{/other_user}","gists_url":"https://api.github.com/users/lukechampine/gists{/gist_id}","starred_url":"https://api.github.com/users/lukechampine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukechampine/subscriptions","organizations_url":"https://api.github.com/users/lukechampine/orgs","repos_url":"https://api.github.com/users/lukechampine/repos","events_url":"https://api.github.com/users/lukechampine/events{/privacy}","received_events_url":"https://api.github.com/users/lukechampine/received_events","type":"User","site_admin":false},"body":"I usually leave out the `''` unless I'm referring to a variable name that isn't easy to parse. The standard library doesn't use them at all. For example:\r\n```go\r\n// Abs returns the absolute value of x.\r\nfunc Abs(x float64) float64\r\n```\r\nHere it's pretty obvious what `x` is referring to, so you don't need any special marks.\r\n```go\r\n// Abs returns an absolute representation of path.\r\nfunc Abs(path string) string\r\n```\r\nHere it's a little less obvious, because `path` doesn't stick out as much as `x`. Still, it's passable.\r\n\r\nTypes, especially exported ones, stand out pretty clearly so they can be typed verbatim. You just need to use your best judgment to decide whether a name will confuse the reader. For example, in docstring of `Fetch`:\r\n```go\r\n// Hosts passed to `ignore` will not be considered.\r\nfunc (ht *HostTree) Fetch(n int, ignore []types.SiaPublicKey)\r\n```\r\nHere, it would be confusing if `ignore` weren't quoted somehow. So surrounding it in single quotes is recommended.","created_at":"2016-12-09T22:52:41Z","updated_at":"2016-12-09T22:52:41Z","html_url":"https://github.com/NebulousLabs/Sia/pull/1513#discussion_r91811372","pull_request_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513","_links":{"self":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments/91811372"},"html":{"href":"https://github.com/NebulousLabs/Sia/pull/1513#discussion_r91811372"},"pull_request":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513"}}},"pull_request":{"url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513","id":97046334,"html_url":"https://github.com/NebulousLabs/Sia/pull/1513","diff_url":"https://github.com/NebulousLabs/Sia/pull/1513.diff","patch_url":"https://github.com/NebulousLabs/Sia/pull/1513.patch","issue_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/1513","number":1513,"state":"open","locked":false,"title":"add hostdb subpackage `hosttree` for storing and retreiving weighted hosts","user":{"login":"johnathanhowell","id":8183920,"avatar_url":"https://avatars.githubusercontent.com/u/8183920?v=3","gravatar_id":"","url":"https://api.github.com/users/johnathanhowell","html_url":"https://github.com/johnathanhowell","followers_url":"https://api.github.com/users/johnathanhowell/followers","following_url":"https://api.github.com/users/johnathanhowell/following{/other_user}","gists_url":"https://api.github.com/users/johnathanhowell/gists{/gist_id}","starred_url":"https://api.github.com/users/johnathanhowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnathanhowell/subscriptions","organizations_url":"https://api.github.com/users/johnathanhowell/orgs","repos_url":"https://api.github.com/users/johnathanhowell/repos","events_url":"https://api.github.com/users/johnathanhowell/events{/privacy}","received_events_url":"https://api.github.com/users/johnathanhowell/received_events","type":"User","site_admin":false},"body":"This PR introduces the `hosttree` subpackage to the renter's hostdb. This package exposes a minimal interface for inserting, deleting, modifying, and fetching hosts from the tree. A later PR will implement this package with the `hostdb`. Most of the testing from the previous `weightedlist` implementation has been preserved. Hosts are now indexed by Public Key instead of NetAddress.","created_at":"2016-12-08T02:07:20Z","updated_at":"2016-12-09T22:52:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"97b958c93817884ee1977277879652f1e07b1a31","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513/commits","review_comments_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513/comments","review_comment_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/1513/comments","statuses_url":"https://api.github.com/repos/NebulousLabs/Sia/statuses/940375cd3207ac0b0b8c7a9b63bcca47d3fd2e5b","head":{"label":"NebulousLabs:hostdb-hosttree","ref":"hostdb-hosttree","sha":"940375cd3207ac0b0b8c7a9b63bcca47d3fd2e5b","user":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":25370072,"name":"Sia","full_name":"NebulousLabs/Sia","owner":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NebulousLabs/Sia","description":"Blockchain-based marketplace for file storage","fork":false,"url":"https://api.github.com/repos/NebulousLabs/Sia","forks_url":"https://api.github.com/repos/NebulousLabs/Sia/forks","keys_url":"https://api.github.com/repos/NebulousLabs/Sia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NebulousLabs/Sia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NebulousLabs/Sia/teams","hooks_url":"https://api.github.com/repos/NebulousLabs/Sia/hooks","issue_events_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/events{/number}","events_url":"https://api.github.com/repos/NebulousLabs/Sia/events","assignees_url":"https://api.github.com/repos/NebulousLabs/Sia/assignees{/user}","branches_url":"https://api.github.com/repos/NebulousLabs/Sia/branches{/branch}","tags_url":"https://api.github.com/repos/NebulousLabs/Sia/tags","blobs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NebulousLabs/Sia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/refs{/sha}","trees_url":"https://api.github.com/repos/NebulousLabs/Sia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NebulousLabs/Sia/statuses/{sha}","languages_url":"https://api.github.com/repos/NebulousLabs/Sia/languages","stargazers_url":"https://api.github.com/repos/NebulousLabs/Sia/stargazers","contributors_url":"https://api.github.com/repos/NebulousLabs/Sia/contributors","subscribers_url":"https://api.github.com/repos/NebulousLabs/Sia/subscribers","subscription_url":"https://api.github.com/repos/NebulousLabs/Sia/subscription","commits_url":"https://api.github.com/repos/NebulousLabs/Sia/commits{/sha}","git_commits_url":"https://api.github.com/repos/NebulousLabs/Sia/git/commits{/sha}","comments_url":"https://api.github.com/repos/NebulousLabs/Sia/comments{/number}","issue_comment_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/comments{/number}","contents_url":"https://api.github.com/repos/NebulousLabs/Sia/contents/{+path}","compare_url":"https://api.github.com/repos/NebulousLabs/Sia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NebulousLabs/Sia/merges","archive_url":"https://api.github.com/repos/NebulousLabs/Sia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NebulousLabs/Sia/downloads","issues_url":"https://api.github.com/repos/NebulousLabs/Sia/issues{/number}","pulls_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls{/number}","milestones_url":"https://api.github.com/repos/NebulousLabs/Sia/milestones{/number}","notifications_url":"https://api.github.com/repos/NebulousLabs/Sia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NebulousLabs/Sia/labels{/name}","releases_url":"https://api.github.com/repos/NebulousLabs/Sia/releases{/id}","deployments_url":"https://api.github.com/repos/NebulousLabs/Sia/deployments","created_at":"2014-10-17T17:50:25Z","updated_at":"2016-12-09T22:21:38Z","pushed_at":"2016-12-09T20:24:47Z","git_url":"git://github.com/NebulousLabs/Sia.git","ssh_url":"git@github.com:NebulousLabs/Sia.git","clone_url":"https://github.com/NebulousLabs/Sia.git","svn_url":"https://github.com/NebulousLabs/Sia","homepage":"https://sia.tech","size":31240,"stargazers_count":418,"watchers_count":418,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":69,"mirror_url":null,"open_issues_count":77,"forks":69,"open_issues":77,"watchers":418,"default_branch":"master"}},"base":{"label":"NebulousLabs:master","ref":"master","sha":"df856ed9df8ddc68b048734e04e48499b38508de","user":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":25370072,"name":"Sia","full_name":"NebulousLabs/Sia","owner":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NebulousLabs/Sia","description":"Blockchain-based marketplace for file storage","fork":false,"url":"https://api.github.com/repos/NebulousLabs/Sia","forks_url":"https://api.github.com/repos/NebulousLabs/Sia/forks","keys_url":"https://api.github.com/repos/NebulousLabs/Sia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NebulousLabs/Sia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NebulousLabs/Sia/teams","hooks_url":"https://api.github.com/repos/NebulousLabs/Sia/hooks","issue_events_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/events{/number}","events_url":"https://api.github.com/repos/NebulousLabs/Sia/events","assignees_url":"https://api.github.com/repos/NebulousLabs/Sia/assignees{/user}","branches_url":"https://api.github.com/repos/NebulousLabs/Sia/branches{/branch}","tags_url":"https://api.github.com/repos/NebulousLabs/Sia/tags","blobs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NebulousLabs/Sia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/refs{/sha}","trees_url":"https://api.github.com/repos/NebulousLabs/Sia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NebulousLabs/Sia/statuses/{sha}","languages_url":"https://api.github.com/repos/NebulousLabs/Sia/languages","stargazers_url":"https://api.github.com/repos/NebulousLabs/Sia/stargazers","contributors_url":"https://api.github.com/repos/NebulousLabs/Sia/contributors","subscribers_url":"https://api.github.com/repos/NebulousLabs/Sia/subscribers","subscription_url":"https://api.github.com/repos/NebulousLabs/Sia/subscription","commits_url":"https://api.github.com/repos/NebulousLabs/Sia/commits{/sha}","git_commits_url":"https://api.github.com/repos/NebulousLabs/Sia/git/commits{/sha}","comments_url":"https://api.github.com/repos/NebulousLabs/Sia/comments{/number}","issue_comment_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/comments{/number}","contents_url":"https://api.github.com/repos/NebulousLabs/Sia/contents/{+path}","compare_url":"https://api.github.com/repos/NebulousLabs/Sia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NebulousLabs/Sia/merges","archive_url":"https://api.github.com/repos/NebulousLabs/Sia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NebulousLabs/Sia/downloads","issues_url":"https://api.github.com/repos/NebulousLabs/Sia/issues{/number}","pulls_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls{/number}","milestones_url":"https://api.github.com/repos/NebulousLabs/Sia/milestones{/number}","notifications_url":"https://api.github.com/repos/NebulousLabs/Sia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NebulousLabs/Sia/labels{/name}","releases_url":"https://api.github.com/repos/NebulousLabs/Sia/releases{/id}","deployments_url":"https://api.github.com/repos/NebulousLabs/Sia/deployments","created_at":"2014-10-17T17:50:25Z","updated_at":"2016-12-09T22:21:38Z","pushed_at":"2016-12-09T20:24:47Z","git_url":"git://github.com/NebulousLabs/Sia.git","ssh_url":"git@github.com:NebulousLabs/Sia.git","clone_url":"https://github.com/NebulousLabs/Sia.git","svn_url":"https://github.com/NebulousLabs/Sia","homepage":"https://sia.tech","size":31240,"stargazers_count":418,"watchers_count":418,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":69,"mirror_url":null,"open_issues_count":77,"forks":69,"open_issues":77,"watchers":418,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513"},"html":{"href":"https://github.com/NebulousLabs/Sia/pull/1513"},"issue":{"href":"https://api.github.com/repos/NebulousLabs/Sia/issues/1513"},"comments":{"href":"https://api.github.com/repos/NebulousLabs/Sia/issues/1513/comments"},"review_comments":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513/comments"},"review_comment":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/1513/commits"},"statuses":{"href":"https://api.github.com/repos/NebulousLabs/Sia/statuses/940375cd3207ac0b0b8c7a9b63bcca47d3fd2e5b"}}}}
{"actor":{"display_login":"lukechampine"}}