{"action":"created","comment":{"url":"https://api.github.com/repos/java-course-au/assignments/pulls/comments/41060599","id":41060599,"diff_hunk":"@@ -0,0 +1,160 @@\n+package ru.spbau.mit;\n+\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.io.OutputStream;\n+import java.util.ArrayList;\n+\n+/**\n+ * Created by n_buga on 22.09.15.\n+ */\n+\n+public class StringSetImpl implements StreamSerializable, StringSet {\n+    private static class Vertex {\n+        private int termVertexLower;\n+        private boolean termVertex;\n+        private Vertex[] links = new Vertex[256];\n+    }\n+\n+    private static final int ENDOFFILE = 9;\n+\n+    @Override\n+    public void serialize(OutputStream out) throws SerializationException {\n+        try {\n+            doSerialize(out);\n+        } catch (IOException e) {\n+            throw new SerializationException(\"serialize\");\n+        }\n+    }\n+\n+    private void doSerialize(OutputStream out) throws IOException {\n+        Vertex curVertex = vertexHead;\n+        StringBuilder curString = new StringBuilder();\n+        goRoundTree(out, curVertex, curString);\n+        out.write((char) ENDOFFILE);\n+    }\n+\n+    private void goRoundTree(OutputStream out, Vertex curVertex, StringBuilder curString) throws IOException {\n+        if (curVertex == null) {\n+            return;\n+        }\n+        if (curVertex.termVertex) {\n+            for (int i = 0; i < curString.length(); i++) {\n+                out.write(curString.charAt(i));\n+            }\n+            out.write('\\n');\n+        }\n+        for (int i = 0; i < 256; i++) {\n+            if (curVertex.links[i] != null) {\n+                curString.append((char)i);\n+                goRoundTree(out, curVertex.links[i], curString);\n+                curString.deleteCharAt(curString.length() - 1);\n+            }\n+        }\n+    }\n+\n+    @Override\n+    public void deserialize(InputStream in) throws SerializationException{\n+        try {\n+            doDeserialize(in);\n+        } catch (IOException e) {\n+            throw new SerializationException(\"deserialize\");\n+        }\n+    }\n+\n+    private void doDeserialize(InputStream in) throws IOException {\n+        vertexHead = new Vertex();\n+        char c = 0;\n+        int i = 0;\n+        while (i != ENDOFFILE) {\n+            StringBuilder curString = new StringBuilder();\n+            i = in.read();\n+            while ((c = (char)i) != '\\n' && i != ENDOFFILE) {\n+                curString.append(c);\n+                i = in.read();\n+            }\n+            if (i == ENDOFFILE) {\n+                break;\n+            }\n+            add(curString.toString());\n+        }\n+    }\n+\n+    private Vertex vertexHead = new Vertex();\n+\n+    @Override\n+    public boolean add(String element){\n+        if (this.contains(element)) {\n+            return false;\n+        }\n+        Vertex currentVertex = vertexHead;\n+        currentVertex.termVertexLower++;\n+        for (char c: element.toCharArray()){\n+            if (currentVertex.links[(int)c] != null) {\n+                currentVertex = currentVertex.links[c];\n+                currentVertex.termVertexLower++;\n+            }\n+            else {\n+                Vertex newVertex = new Vertex();\n+                currentVertex.links[(int)c] = newVertex;\n+                currentVertex = currentVertex.links[c];\n+                currentVertex.termVertexLower++;\n+            }\n+        }\n+        currentVertex.termVertex = true;\n+        return true;\n+    }\n+\n+    @Override\n+    public boolean contains(String element) {\n+        Vertex curVertex = vertexHead;\n+        int i;\n+        for (i = 0; i < element.length(); i++) {\n+            if (curVertex.links[element.charAt(i)] == null) {\n+                return false;\n+            }\n+            curVertex = curVertex.links[element.charAt(i)];\n+        }\n+        return curVertex.termVertex;\n+    }\n+\n+    @Override\n+    public boolean remove(String element) {\n+        if (!this.contains(element)) {\n+            return false;\n+        }\n+        Vertex curVertex = vertexHead;\n+        for (int i = 0; i < element.length(); i++){\n+            if (curVertex.termVertexLower > 1 && curVertex.links[element.charAt(i)].termVertexLower == 1) {\n+                curVertex.termVertexLower--;\n+                curVertex.links[element.charAt(i)] = null;\n+                return true;\n+            }\n+            else {\n+                curVertex.termVertexLower--;\n+                curVertex = curVertex.links[element.charAt(i)];\n+            }\n+        }\n+        curVertex.termVertex = false;\n+        curVertex.termVertexLower--;\n+        return true;\n+    }\n+\n+    @Override\n+    public int size() {\n+        return vertexHead.termVertexLower;\n+    }\n+\n+    @Override\n+    public int howManyStartsWithPrefix(String prefix) {\n+        int i;\n+        Vertex curVertex = vertexHead;","path":"src/main/java/ru/spbau/mit/StringSetImpl.java","position":151,"original_position":151,"commit_id":"4e697711852830267fe0d994bee3165a9851d6d3","original_commit_id":"4e697711852830267fe0d994bee3165a9851d6d3","user":{"login":"dzharkov","id":863207,"avatar_url":"https://avatars.githubusercontent.com/u/863207?v=3","gravatar_id":"","url":"https://api.github.com/users/dzharkov","html_url":"https://github.com/dzharkov","followers_url":"https://api.github.com/users/dzharkov/followers","following_url":"https://api.github.com/users/dzharkov/following{/other_user}","gists_url":"https://api.github.com/users/dzharkov/gists{/gist_id}","starred_url":"https://api.github.com/users/dzharkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dzharkov/subscriptions","organizations_url":"https://api.github.com/users/dzharkov/orgs","repos_url":"https://api.github.com/users/dzharkov/repos","events_url":"https://api.github.com/users/dzharkov/events{/privacy}","received_events_url":"https://api.github.com/users/dzharkov/received_events","type":"User","site_admin":false},"body":"Метод howManyStartsWithPrefix похож на remove.\r\nВыдели общую логику в отдельный метод","created_at":"2015-10-02T19:50:00Z","updated_at":"2015-10-02T19:50:00Z","html_url":"https://github.com/java-course-au/assignments/pull/20#discussion_r41060599","pull_request_url":"https://api.github.com/repos/java-course-au/assignments/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/comments/41060599"},"html":{"href":"https://github.com/java-course-au/assignments/pull/20#discussion_r41060599"},"pull_request":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/java-course-au/assignments/pulls/20","id":45672890,"html_url":"https://github.com/java-course-au/assignments/pull/20","diff_url":"https://github.com/java-course-au/assignments/pull/20.diff","patch_url":"https://github.com/java-course-au/assignments/pull/20.patch","issue_url":"https://api.github.com/repos/java-course-au/assignments/issues/20","number":20,"state":"open","locked":false,"title":"01 serializable string set","user":{"login":"N-buga","id":10629368,"avatar_url":"https://avatars.githubusercontent.com/u/10629368?v=3","gravatar_id":"","url":"https://api.github.com/users/N-buga","html_url":"https://github.com/N-buga","followers_url":"https://api.github.com/users/N-buga/followers","following_url":"https://api.github.com/users/N-buga/following{/other_user}","gists_url":"https://api.github.com/users/N-buga/gists{/gist_id}","starred_url":"https://api.github.com/users/N-buga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N-buga/subscriptions","organizations_url":"https://api.github.com/users/N-buga/orgs","repos_url":"https://api.github.com/users/N-buga/repos","events_url":"https://api.github.com/users/N-buga/events{/privacy}","received_events_url":"https://api.github.com/users/N-buga/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-22T14:50:38Z","updated_at":"2015-10-02T19:50:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bea92d99ef03bd8d8f3e9c5f0b9469f0bc54e09a","assignee":{"login":"dzharkov","id":863207,"avatar_url":"https://avatars.githubusercontent.com/u/863207?v=3","gravatar_id":"","url":"https://api.github.com/users/dzharkov","html_url":"https://github.com/dzharkov","followers_url":"https://api.github.com/users/dzharkov/followers","following_url":"https://api.github.com/users/dzharkov/following{/other_user}","gists_url":"https://api.github.com/users/dzharkov/gists{/gist_id}","starred_url":"https://api.github.com/users/dzharkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dzharkov/subscriptions","organizations_url":"https://api.github.com/users/dzharkov/orgs","repos_url":"https://api.github.com/users/dzharkov/repos","events_url":"https://api.github.com/users/dzharkov/events{/privacy}","received_events_url":"https://api.github.com/users/dzharkov/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/java-course-au/assignments/pulls/20/commits","review_comments_url":"https://api.github.com/repos/java-course-au/assignments/pulls/20/comments","review_comment_url":"https://api.github.com/repos/java-course-au/assignments/pulls/comments{/number}","comments_url":"https://api.github.com/repos/java-course-au/assignments/issues/20/comments","statuses_url":"https://api.github.com/repos/java-course-au/assignments/statuses/4e697711852830267fe0d994bee3165a9851d6d3","head":{"label":"N-buga:01-serializable-string-set","ref":"01-serializable-string-set","sha":"4e697711852830267fe0d994bee3165a9851d6d3","user":{"login":"N-buga","id":10629368,"avatar_url":"https://avatars.githubusercontent.com/u/10629368?v=3","gravatar_id":"","url":"https://api.github.com/users/N-buga","html_url":"https://github.com/N-buga","followers_url":"https://api.github.com/users/N-buga/followers","following_url":"https://api.github.com/users/N-buga/following{/other_user}","gists_url":"https://api.github.com/users/N-buga/gists{/gist_id}","starred_url":"https://api.github.com/users/N-buga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N-buga/subscriptions","organizations_url":"https://api.github.com/users/N-buga/orgs","repos_url":"https://api.github.com/users/N-buga/repos","events_url":"https://api.github.com/users/N-buga/events{/privacy}","received_events_url":"https://api.github.com/users/N-buga/received_events","type":"User","site_admin":false},"repo":{"id":42873747,"name":"assignments","full_name":"N-buga/assignments","owner":{"login":"N-buga","id":10629368,"avatar_url":"https://avatars.githubusercontent.com/u/10629368?v=3","gravatar_id":"","url":"https://api.github.com/users/N-buga","html_url":"https://github.com/N-buga","followers_url":"https://api.github.com/users/N-buga/followers","following_url":"https://api.github.com/users/N-buga/following{/other_user}","gists_url":"https://api.github.com/users/N-buga/gists{/gist_id}","starred_url":"https://api.github.com/users/N-buga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/N-buga/subscriptions","organizations_url":"https://api.github.com/users/N-buga/orgs","repos_url":"https://api.github.com/users/N-buga/repos","events_url":"https://api.github.com/users/N-buga/events{/privacy}","received_events_url":"https://api.github.com/users/N-buga/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/N-buga/assignments","description":"Домашние задания по Java","fork":true,"url":"https://api.github.com/repos/N-buga/assignments","forks_url":"https://api.github.com/repos/N-buga/assignments/forks","keys_url":"https://api.github.com/repos/N-buga/assignments/keys{/key_id}","collaborators_url":"https://api.github.com/repos/N-buga/assignments/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/N-buga/assignments/teams","hooks_url":"https://api.github.com/repos/N-buga/assignments/hooks","issue_events_url":"https://api.github.com/repos/N-buga/assignments/issues/events{/number}","events_url":"https://api.github.com/repos/N-buga/assignments/events","assignees_url":"https://api.github.com/repos/N-buga/assignments/assignees{/user}","branches_url":"https://api.github.com/repos/N-buga/assignments/branches{/branch}","tags_url":"https://api.github.com/repos/N-buga/assignments/tags","blobs_url":"https://api.github.com/repos/N-buga/assignments/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/N-buga/assignments/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/N-buga/assignments/git/refs{/sha}","trees_url":"https://api.github.com/repos/N-buga/assignments/git/trees{/sha}","statuses_url":"https://api.github.com/repos/N-buga/assignments/statuses/{sha}","languages_url":"https://api.github.com/repos/N-buga/assignments/languages","stargazers_url":"https://api.github.com/repos/N-buga/assignments/stargazers","contributors_url":"https://api.github.com/repos/N-buga/assignments/contributors","subscribers_url":"https://api.github.com/repos/N-buga/assignments/subscribers","subscription_url":"https://api.github.com/repos/N-buga/assignments/subscription","commits_url":"https://api.github.com/repos/N-buga/assignments/commits{/sha}","git_commits_url":"https://api.github.com/repos/N-buga/assignments/git/commits{/sha}","comments_url":"https://api.github.com/repos/N-buga/assignments/comments{/number}","issue_comment_url":"https://api.github.com/repos/N-buga/assignments/issues/comments{/number}","contents_url":"https://api.github.com/repos/N-buga/assignments/contents/{+path}","compare_url":"https://api.github.com/repos/N-buga/assignments/compare/{base}...{head}","merges_url":"https://api.github.com/repos/N-buga/assignments/merges","archive_url":"https://api.github.com/repos/N-buga/assignments/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/N-buga/assignments/downloads","issues_url":"https://api.github.com/repos/N-buga/assignments/issues{/number}","pulls_url":"https://api.github.com/repos/N-buga/assignments/pulls{/number}","milestones_url":"https://api.github.com/repos/N-buga/assignments/milestones{/number}","notifications_url":"https://api.github.com/repos/N-buga/assignments/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/N-buga/assignments/labels{/name}","releases_url":"https://api.github.com/repos/N-buga/assignments/releases{/id}","created_at":"2015-09-21T15:05:15Z","updated_at":"2015-09-15T08:01:56Z","pushed_at":"2015-09-30T20:16:26Z","git_url":"git://github.com/N-buga/assignments.git","ssh_url":"git@github.com:N-buga/assignments.git","clone_url":"https://github.com/N-buga/assignments.git","svn_url":"https://github.com/N-buga/assignments","homepage":"http://mit.spbau.ru/sewiki/index.php/Java_2_2015","size":163,"stargazers_count":0,"watchers_count":0,"language":null,"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":"java-course-au:01-serializable-string-set","ref":"01-serializable-string-set","sha":"9dbb9b31cfc63f8250a07c5b408ada65c27a86e6","user":{"login":"java-course-au","id":14248092,"avatar_url":"https://avatars.githubusercontent.com/u/14248092?v=3","gravatar_id":"","url":"https://api.github.com/users/java-course-au","html_url":"https://github.com/java-course-au","followers_url":"https://api.github.com/users/java-course-au/followers","following_url":"https://api.github.com/users/java-course-au/following{/other_user}","gists_url":"https://api.github.com/users/java-course-au/gists{/gist_id}","starred_url":"https://api.github.com/users/java-course-au/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/java-course-au/subscriptions","organizations_url":"https://api.github.com/users/java-course-au/orgs","repos_url":"https://api.github.com/users/java-course-au/repos","events_url":"https://api.github.com/users/java-course-au/events{/privacy}","received_events_url":"https://api.github.com/users/java-course-au/received_events","type":"Organization","site_admin":false},"repo":{"id":42502722,"name":"assignments","full_name":"java-course-au/assignments","owner":{"login":"java-course-au","id":14248092,"avatar_url":"https://avatars.githubusercontent.com/u/14248092?v=3","gravatar_id":"","url":"https://api.github.com/users/java-course-au","html_url":"https://github.com/java-course-au","followers_url":"https://api.github.com/users/java-course-au/followers","following_url":"https://api.github.com/users/java-course-au/following{/other_user}","gists_url":"https://api.github.com/users/java-course-au/gists{/gist_id}","starred_url":"https://api.github.com/users/java-course-au/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/java-course-au/subscriptions","organizations_url":"https://api.github.com/users/java-course-au/orgs","repos_url":"https://api.github.com/users/java-course-au/repos","events_url":"https://api.github.com/users/java-course-au/events{/privacy}","received_events_url":"https://api.github.com/users/java-course-au/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/java-course-au/assignments","description":"Домашние задания по Java","fork":false,"url":"https://api.github.com/repos/java-course-au/assignments","forks_url":"https://api.github.com/repos/java-course-au/assignments/forks","keys_url":"https://api.github.com/repos/java-course-au/assignments/keys{/key_id}","collaborators_url":"https://api.github.com/repos/java-course-au/assignments/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/java-course-au/assignments/teams","hooks_url":"https://api.github.com/repos/java-course-au/assignments/hooks","issue_events_url":"https://api.github.com/repos/java-course-au/assignments/issues/events{/number}","events_url":"https://api.github.com/repos/java-course-au/assignments/events","assignees_url":"https://api.github.com/repos/java-course-au/assignments/assignees{/user}","branches_url":"https://api.github.com/repos/java-course-au/assignments/branches{/branch}","tags_url":"https://api.github.com/repos/java-course-au/assignments/tags","blobs_url":"https://api.github.com/repos/java-course-au/assignments/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/java-course-au/assignments/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/java-course-au/assignments/git/refs{/sha}","trees_url":"https://api.github.com/repos/java-course-au/assignments/git/trees{/sha}","statuses_url":"https://api.github.com/repos/java-course-au/assignments/statuses/{sha}","languages_url":"https://api.github.com/repos/java-course-au/assignments/languages","stargazers_url":"https://api.github.com/repos/java-course-au/assignments/stargazers","contributors_url":"https://api.github.com/repos/java-course-au/assignments/contributors","subscribers_url":"https://api.github.com/repos/java-course-au/assignments/subscribers","subscription_url":"https://api.github.com/repos/java-course-au/assignments/subscription","commits_url":"https://api.github.com/repos/java-course-au/assignments/commits{/sha}","git_commits_url":"https://api.github.com/repos/java-course-au/assignments/git/commits{/sha}","comments_url":"https://api.github.com/repos/java-course-au/assignments/comments{/number}","issue_comment_url":"https://api.github.com/repos/java-course-au/assignments/issues/comments{/number}","contents_url":"https://api.github.com/repos/java-course-au/assignments/contents/{+path}","compare_url":"https://api.github.com/repos/java-course-au/assignments/compare/{base}...{head}","merges_url":"https://api.github.com/repos/java-course-au/assignments/merges","archive_url":"https://api.github.com/repos/java-course-au/assignments/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/java-course-au/assignments/downloads","issues_url":"https://api.github.com/repos/java-course-au/assignments/issues{/number}","pulls_url":"https://api.github.com/repos/java-course-au/assignments/pulls{/number}","milestones_url":"https://api.github.com/repos/java-course-au/assignments/milestones{/number}","notifications_url":"https://api.github.com/repos/java-course-au/assignments/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/java-course-au/assignments/labels{/name}","releases_url":"https://api.github.com/repos/java-course-au/assignments/releases{/id}","created_at":"2015-09-15T07:36:54Z","updated_at":"2015-09-29T21:09:52Z","pushed_at":"2015-10-02T14:54:54Z","git_url":"git://github.com/java-course-au/assignments.git","ssh_url":"git@github.com:java-course-au/assignments.git","clone_url":"https://github.com/java-course-au/assignments.git","svn_url":"https://github.com/java-course-au/assignments","homepage":"http://mit.spbau.ru/sewiki/index.php/Java_2_2015","size":1467,"stargazers_count":3,"watchers_count":3,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":26,"forks":26,"open_issues":26,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/20"},"html":{"href":"https://github.com/java-course-au/assignments/pull/20"},"issue":{"href":"https://api.github.com/repos/java-course-au/assignments/issues/20"},"comments":{"href":"https://api.github.com/repos/java-course-au/assignments/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/java-course-au/assignments/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/java-course-au/assignments/statuses/4e697711852830267fe0d994bee3165a9851d6d3"}}}}