{"action":"created","comment":{"url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/comments/43344364","id":43344364,"diff_hunk":"@@ -0,0 +1,146 @@\n+package com.yahoo.sketches.counting;\n+\n+import java.util.Collection;\n+import java.util.HashMap;\n+import java.util.Map.Entry;\n+import java.util.ArrayList;\n+\n+/**\n+ * This is a utility class that implements (and abstracts) a set of positive counters. \n+ * The mapping is  Long key -> Long count.\n+ * The default value of any key is zero and no negative counters are allowed. \n+ * Non-positive mappings are deleted. \n+ * \n+ * It also support incrementing individual counters and decrementing all counters simultaneously.\n+ * This is a convenient and efficient modification intended to be used in FrequentDirection sketching.\n+ * \n+ * @author edo \n+ */\n+public class PositiveCountersMap{\n+  \n+  private HashMap<Long,Long> counters;\n+  ArrayList<Long> keysToRemove;\n+  private long offset;\n+  private long nnz;\n+\n+  /**\n+   * Creates empty mappings and default offset = 0.\n+   */\n+  public PositiveCountersMap(){\n+    counters = new HashMap<Long,Long>();\n+    keysToRemove = new ArrayList<Long>();\n+    offset = 0L;\n+  }\n+  \n+  /**\n+   * @return the number of positive counters\n+   */\n+  public long nnz(){\n+    return nnz;\n+  }\n+  \n+  /**\n+   * @return an iterator over the positive count values \n+   */\n+  public Collection<Long> values(){\n+    return counters.values();\n+  }\n+  \n+  /**\n+   * @return an iterator over the keys corresponding to positive counts only\n+   */\n+  public Collection<Long> keys(){\n+    return counters.keySet();\n+  }\n+  \n+  /**\n+   * @param key, should not be null.\n+   * @return the exact count for that key.\n+   */\n+  public Long get(Long key){","path":"src/main/java/com/yahoo/sketches/counting/PositiveCountersMap.java","position":60,"original_position":60,"commit_id":"3d7484fe44cb4af5459e420f187abd77f1fd573d","original_commit_id":"3d7484fe44cb4af5459e420f187abd77f1fd573d","user":{"login":"leerho","id":12941506,"avatar_url":"https://avatars.githubusercontent.com/u/12941506?v=3","gravatar_id":"","url":"https://api.github.com/users/leerho","html_url":"https://github.com/leerho","followers_url":"https://api.github.com/users/leerho/followers","following_url":"https://api.github.com/users/leerho/following{/other_user}","gists_url":"https://api.github.com/users/leerho/gists{/gist_id}","starred_url":"https://api.github.com/users/leerho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leerho/subscriptions","organizations_url":"https://api.github.com/users/leerho/orgs","repos_url":"https://api.github.com/users/leerho/repos","events_url":"https://api.github.com/users/leerho/events{/privacy}","received_events_url":"https://api.github.com/users/leerho/received_events","type":"User","site_admin":false},"body":"Why does the user need the Long vs a long as the return value? especially if it could be null?  Again, hide the use of the object wrappers from the user.  This will also eliminate the need to check for nulls, as the run-time will automatically throw a null exception if the Long is null in attempting to convert to long.\r\n\r\nBe aware that in Java, \"assert\" is enabled during unit tests, but by default disabled for normal operation.  The proper way to check parameters provided by the user is to check:  \r\nif (key == null) throw new IllegalArgumentException(\"cause...\");  \r\nThus the unit tests can and should exercise the limits of mathematical correctness, and then use asserts within the code to validate internal state.   Asserts can be enabled for a running program by adding \"-ea\" to the JVM arguments.   But in big pipeline operations this is only done as a last resort when troubleshooting a problem.","created_at":"2015-10-29T02:56:47Z","updated_at":"2015-10-29T02:56:47Z","html_url":"https://github.com/DataSketches/sketches-core/pull/16#discussion_r43344364","pull_request_url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/comments/43344364"},"html":{"href":"https://github.com/DataSketches/sketches-core/pull/16#discussion_r43344364"},"pull_request":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16","id":48407712,"html_url":"https://github.com/DataSketches/sketches-core/pull/16","diff_url":"https://github.com/DataSketches/sketches-core/pull/16.diff","patch_url":"https://github.com/DataSketches/sketches-core/pull/16.patch","issue_url":"https://api.github.com/repos/DataSketches/sketches-core/issues/16","number":16,"state":"open","locked":false,"title":"Frequent Items basic implementation","user":{"login":"edoliberty","id":12585081,"avatar_url":"https://avatars.githubusercontent.com/u/12585081?v=3","gravatar_id":"","url":"https://api.github.com/users/edoliberty","html_url":"https://github.com/edoliberty","followers_url":"https://api.github.com/users/edoliberty/followers","following_url":"https://api.github.com/users/edoliberty/following{/other_user}","gists_url":"https://api.github.com/users/edoliberty/gists{/gist_id}","starred_url":"https://api.github.com/users/edoliberty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edoliberty/subscriptions","organizations_url":"https://api.github.com/users/edoliberty/orgs","repos_url":"https://api.github.com/users/edoliberty/repos","events_url":"https://api.github.com/users/edoliberty/events{/privacy}","received_events_url":"https://api.github.com/users/edoliberty/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-22T01:14:46Z","updated_at":"2015-10-29T02:56:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88b1ab5cfa91f11e2053753fb23fa5b05f58f8e5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16/commits","review_comments_url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16/comments","review_comment_url":"https://api.github.com/repos/DataSketches/sketches-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataSketches/sketches-core/issues/16/comments","statuses_url":"https://api.github.com/repos/DataSketches/sketches-core/statuses/3d7484fe44cb4af5459e420f187abd77f1fd573d","head":{"label":"edoliberty:master","ref":"master","sha":"3d7484fe44cb4af5459e420f187abd77f1fd573d","user":{"login":"edoliberty","id":12585081,"avatar_url":"https://avatars.githubusercontent.com/u/12585081?v=3","gravatar_id":"","url":"https://api.github.com/users/edoliberty","html_url":"https://github.com/edoliberty","followers_url":"https://api.github.com/users/edoliberty/followers","following_url":"https://api.github.com/users/edoliberty/following{/other_user}","gists_url":"https://api.github.com/users/edoliberty/gists{/gist_id}","starred_url":"https://api.github.com/users/edoliberty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edoliberty/subscriptions","organizations_url":"https://api.github.com/users/edoliberty/orgs","repos_url":"https://api.github.com/users/edoliberty/repos","events_url":"https://api.github.com/users/edoliberty/events{/privacy}","received_events_url":"https://api.github.com/users/edoliberty/received_events","type":"User","site_admin":false},"repo":{"id":44536876,"name":"sketches-core","full_name":"edoliberty/sketches-core","owner":{"login":"edoliberty","id":12585081,"avatar_url":"https://avatars.githubusercontent.com/u/12585081?v=3","gravatar_id":"","url":"https://api.github.com/users/edoliberty","html_url":"https://github.com/edoliberty","followers_url":"https://api.github.com/users/edoliberty/followers","following_url":"https://api.github.com/users/edoliberty/following{/other_user}","gists_url":"https://api.github.com/users/edoliberty/gists{/gist_id}","starred_url":"https://api.github.com/users/edoliberty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edoliberty/subscriptions","organizations_url":"https://api.github.com/users/edoliberty/orgs","repos_url":"https://api.github.com/users/edoliberty/repos","events_url":"https://api.github.com/users/edoliberty/events{/privacy}","received_events_url":"https://api.github.com/users/edoliberty/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edoliberty/sketches-core","description":"Core Sketch Library","fork":true,"url":"https://api.github.com/repos/edoliberty/sketches-core","forks_url":"https://api.github.com/repos/edoliberty/sketches-core/forks","keys_url":"https://api.github.com/repos/edoliberty/sketches-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edoliberty/sketches-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edoliberty/sketches-core/teams","hooks_url":"https://api.github.com/repos/edoliberty/sketches-core/hooks","issue_events_url":"https://api.github.com/repos/edoliberty/sketches-core/issues/events{/number}","events_url":"https://api.github.com/repos/edoliberty/sketches-core/events","assignees_url":"https://api.github.com/repos/edoliberty/sketches-core/assignees{/user}","branches_url":"https://api.github.com/repos/edoliberty/sketches-core/branches{/branch}","tags_url":"https://api.github.com/repos/edoliberty/sketches-core/tags","blobs_url":"https://api.github.com/repos/edoliberty/sketches-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edoliberty/sketches-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edoliberty/sketches-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/edoliberty/sketches-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edoliberty/sketches-core/statuses/{sha}","languages_url":"https://api.github.com/repos/edoliberty/sketches-core/languages","stargazers_url":"https://api.github.com/repos/edoliberty/sketches-core/stargazers","contributors_url":"https://api.github.com/repos/edoliberty/sketches-core/contributors","subscribers_url":"https://api.github.com/repos/edoliberty/sketches-core/subscribers","subscription_url":"https://api.github.com/repos/edoliberty/sketches-core/subscription","commits_url":"https://api.github.com/repos/edoliberty/sketches-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/edoliberty/sketches-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/edoliberty/sketches-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/edoliberty/sketches-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/edoliberty/sketches-core/contents/{+path}","compare_url":"https://api.github.com/repos/edoliberty/sketches-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edoliberty/sketches-core/merges","archive_url":"https://api.github.com/repos/edoliberty/sketches-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edoliberty/sketches-core/downloads","issues_url":"https://api.github.com/repos/edoliberty/sketches-core/issues{/number}","pulls_url":"https://api.github.com/repos/edoliberty/sketches-core/pulls{/number}","milestones_url":"https://api.github.com/repos/edoliberty/sketches-core/milestones{/number}","notifications_url":"https://api.github.com/repos/edoliberty/sketches-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edoliberty/sketches-core/labels{/name}","releases_url":"https://api.github.com/repos/edoliberty/sketches-core/releases{/id}","created_at":"2015-10-19T13:31:20Z","updated_at":"2015-10-19T13:31:21Z","pushed_at":"2015-10-28T18:01:09Z","git_url":"git://github.com/edoliberty/sketches-core.git","ssh_url":"git@github.com:edoliberty/sketches-core.git","clone_url":"https://github.com/edoliberty/sketches-core.git","svn_url":"https://github.com/edoliberty/sketches-core","homepage":null,"size":2762,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"DataSketches:master","ref":"master","sha":"66348e8277e5731351484782607697ad2d40c427","user":{"login":"DataSketches","id":12956085,"avatar_url":"https://avatars.githubusercontent.com/u/12956085?v=3","gravatar_id":"","url":"https://api.github.com/users/DataSketches","html_url":"https://github.com/DataSketches","followers_url":"https://api.github.com/users/DataSketches/followers","following_url":"https://api.github.com/users/DataSketches/following{/other_user}","gists_url":"https://api.github.com/users/DataSketches/gists{/gist_id}","starred_url":"https://api.github.com/users/DataSketches/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataSketches/subscriptions","organizations_url":"https://api.github.com/users/DataSketches/orgs","repos_url":"https://api.github.com/users/DataSketches/repos","events_url":"https://api.github.com/users/DataSketches/events{/privacy}","received_events_url":"https://api.github.com/users/DataSketches/received_events","type":"Organization","site_admin":false},"repo":{"id":38279790,"name":"sketches-core","full_name":"DataSketches/sketches-core","owner":{"login":"DataSketches","id":12956085,"avatar_url":"https://avatars.githubusercontent.com/u/12956085?v=3","gravatar_id":"","url":"https://api.github.com/users/DataSketches","html_url":"https://github.com/DataSketches","followers_url":"https://api.github.com/users/DataSketches/followers","following_url":"https://api.github.com/users/DataSketches/following{/other_user}","gists_url":"https://api.github.com/users/DataSketches/gists{/gist_id}","starred_url":"https://api.github.com/users/DataSketches/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataSketches/subscriptions","organizations_url":"https://api.github.com/users/DataSketches/orgs","repos_url":"https://api.github.com/users/DataSketches/repos","events_url":"https://api.github.com/users/DataSketches/events{/privacy}","received_events_url":"https://api.github.com/users/DataSketches/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataSketches/sketches-core","description":"Core Sketch Library","fork":false,"url":"https://api.github.com/repos/DataSketches/sketches-core","forks_url":"https://api.github.com/repos/DataSketches/sketches-core/forks","keys_url":"https://api.github.com/repos/DataSketches/sketches-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataSketches/sketches-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataSketches/sketches-core/teams","hooks_url":"https://api.github.com/repos/DataSketches/sketches-core/hooks","issue_events_url":"https://api.github.com/repos/DataSketches/sketches-core/issues/events{/number}","events_url":"https://api.github.com/repos/DataSketches/sketches-core/events","assignees_url":"https://api.github.com/repos/DataSketches/sketches-core/assignees{/user}","branches_url":"https://api.github.com/repos/DataSketches/sketches-core/branches{/branch}","tags_url":"https://api.github.com/repos/DataSketches/sketches-core/tags","blobs_url":"https://api.github.com/repos/DataSketches/sketches-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataSketches/sketches-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataSketches/sketches-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataSketches/sketches-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataSketches/sketches-core/statuses/{sha}","languages_url":"https://api.github.com/repos/DataSketches/sketches-core/languages","stargazers_url":"https://api.github.com/repos/DataSketches/sketches-core/stargazers","contributors_url":"https://api.github.com/repos/DataSketches/sketches-core/contributors","subscribers_url":"https://api.github.com/repos/DataSketches/sketches-core/subscribers","subscription_url":"https://api.github.com/repos/DataSketches/sketches-core/subscription","commits_url":"https://api.github.com/repos/DataSketches/sketches-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataSketches/sketches-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataSketches/sketches-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataSketches/sketches-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataSketches/sketches-core/contents/{+path}","compare_url":"https://api.github.com/repos/DataSketches/sketches-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataSketches/sketches-core/merges","archive_url":"https://api.github.com/repos/DataSketches/sketches-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataSketches/sketches-core/downloads","issues_url":"https://api.github.com/repos/DataSketches/sketches-core/issues{/number}","pulls_url":"https://api.github.com/repos/DataSketches/sketches-core/pulls{/number}","milestones_url":"https://api.github.com/repos/DataSketches/sketches-core/milestones{/number}","notifications_url":"https://api.github.com/repos/DataSketches/sketches-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataSketches/sketches-core/labels{/name}","releases_url":"https://api.github.com/repos/DataSketches/sketches-core/releases{/id}","created_at":"2015-06-30T01:05:21Z","updated_at":"2015-09-22T19:33:32Z","pushed_at":"2015-10-28T19:56:12Z","git_url":"git://github.com/DataSketches/sketches-core.git","ssh_url":"git@github.com:DataSketches/sketches-core.git","clone_url":"https://github.com/DataSketches/sketches-core.git","svn_url":"https://github.com/DataSketches/sketches-core","homepage":null,"size":3136,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":2,"forks":6,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16"},"html":{"href":"https://github.com/DataSketches/sketches-core/pull/16"},"issue":{"href":"https://api.github.com/repos/DataSketches/sketches-core/issues/16"},"comments":{"href":"https://api.github.com/repos/DataSketches/sketches-core/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataSketches/sketches-core/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/DataSketches/sketches-core/statuses/3d7484fe44cb4af5459e420f187abd77f1fd573d"}}}}