{"action":"created","comment":{"url":"https://api.github.com/repos/binast/binjs-ref/pulls/comments/233687015","pull_request_review_id":175151207,"id":233687015,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMzY4NzAxNQ==","diff_hunk":"@@ -336,3 +346,172 @@ impl<NodeValue> PathPredict<NodeValue, SymbolInfo> where NodeValue: Eq + Hash +\n     }\n }\n \n+\n+\n+\n+\n+#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]\n+enum WindowPrediction {\n+    BackReference(BackReference),\n+    DictionaryIndex(DictionaryIndex),\n+}\n+\n+\n+#[derive(Clone, Debug, Serialize, Deserialize)]\n+pub struct WindowPredict<NodeValue, Statistics> where NodeValue: Clone + Eq + Hash {\n+    /// The window width\n+    width: usize,\n+\n+    /// All the known values.\n+    value_by_dictionary_index: Vec<NodeValue>,\n+    dictionary_index_by_value: HashMap<NodeValue, DictionaryIndex>,\n+\n+    latest_values: Vec<NodeValue>,\n+\n+    info: ContextInformation<WindowPrediction, Statistics>,\n+}\n+impl<NodeValue, Statistics> WindowPredict<NodeValue, Statistics> where NodeValue: Clone + Eq + Hash {\n+    pub fn new(width: usize) -> Self {\n+        WindowPredict {\n+            width,\n+            value_by_dictionary_index: Vec::with_capacity(1024), // FIXME: Magic number\n+            dictionary_index_by_value: HashMap::with_capacity(1024),\n+            latest_values: Vec::with_capacity(width),\n+            info: ContextInformation::new(),\n+        }\n+    }\n+\n+    /// Update current window by moving an index to the first position.\n+    fn update_window_by_index(&mut self, index: BackReference) -> Result<BackReference, ()> {\n+        let as_usize: usize = index.into();\n+        if as_usize >= self.latest_values.len() {\n+            return Err(());\n+        }\n+        let ref mut slice = self.latest_values\n+            .as_mut_slice()\n+            [0..index.into()];\n+        slice.rotate_right(1);\n+        Ok(index)\n+    }\n+\n+    /// Update current window by putting a value to the first position.\n+    ///\n+    /// If the value is already in the window, it is moved to the first position,\n+    /// otherwise, it is added. If the resulting window is too large, it is truncated.\n+    fn update_window_by_value(&mut self, value: &NodeValue) -> Option<BackReference> {\n+        // It's possible that the value was present in the window.\n+        if let Some(index) = self.latest_values\n+            .iter()\n+            .position(|v| v == value)\n+        {\n+            return Some(self.update_window_by_index(BackReference(index))\n+                .unwrap())\n+        }\n+        if self.latest_values.len() < self.width {\n+            // If the window isn't full yet, simply add the value at start.\n+            self.latest_values.insert(0, value.clone());\n+        } else {\n+            // Otherwise, rotate.\n+            let slice = self.latest_values\n+                .as_mut_slice();\n+            slice[slice.len() - 1] = value.clone();\n+            slice.rotate_right(1);\n+        }\n+        None\n+    }\n+}\n+impl<NodeValue> WindowPredict<NodeValue, Instances> where NodeValue: Clone + Eq + std::hash::Hash + std::fmt::Debug {\n+    pub fn add(&mut self, value: NodeValue) {\n+        // --- At this stage, we don't know whether the value is known.\n+\n+        let number_of_values = self.value_by_dictionary_index.len();\n+        let dictionary_index = *self.dictionary_index_by_value.entry(value.clone())\n+            .or_insert(DictionaryIndex(number_of_values));\n+\n+        if dictionary_index == DictionaryIndex(number_of_values) {\n+            // We've just inserted `value`.\n+            self.value_by_dictionary_index.push(value.clone());\n+        } else {\n+            // Value was already known.\n+            let index : usize = dictionary_index.into();","path":"crates/binjs_io/src/entropy/predict.rs","position":108,"original_position":108,"commit_id":"f2d765dfce73ebf71f0672721704bb4fdf57ce2c","original_commit_id":"44e1035eee755459ed9644a4db7f78b1cb481e9d","user":{"login":"arai-a","id":6299746,"node_id":"MDQ6VXNlcjYyOTk3NDY=","avatar_url":"https://avatars1.githubusercontent.com/u/6299746?v=4","gravatar_id":"","url":"https://api.github.com/users/arai-a","html_url":"https://github.com/arai-a","followers_url":"https://api.github.com/users/arai-a/followers","following_url":"https://api.github.com/users/arai-a/following{/other_user}","gists_url":"https://api.github.com/users/arai-a/gists{/gist_id}","starred_url":"https://api.github.com/users/arai-a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arai-a/subscriptions","organizations_url":"https://api.github.com/users/arai-a/orgs","repos_url":"https://api.github.com/users/arai-a/repos","events_url":"https://api.github.com/users/arai-a/events{/privacy}","received_events_url":"https://api.github.com/users/arai-a/received_events","type":"User","site_admin":false},"body":"won't this hit unused variable on non-debug build?\r\n(I don't know much about debug/non-debug build difference and warning system tho)","created_at":"2018-11-15T01:44:15Z","updated_at":"2018-11-15T01:54:05Z","html_url":"https://github.com/binast/binjs-ref/pull/201#discussion_r233687015","pull_request_url":"https://api.github.com/repos/binast/binjs-ref/pulls/201","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/comments/233687015"},"html":{"href":"https://github.com/binast/binjs-ref/pull/201#discussion_r233687015"},"pull_request":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/201"}}},"pull_request":{"url":"https://api.github.com/repos/binast/binjs-ref/pulls/201","id":230915716,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwOTE1NzE2","html_url":"https://github.com/binast/binjs-ref/pull/201","diff_url":"https://github.com/binast/binjs-ref/pull/201.diff","patch_url":"https://github.com/binast/binjs-ref/pull/201.patch","issue_url":"https://api.github.com/repos/binast/binjs-ref/issues/201","number":201,"state":"open","locked":false,"title":"Entropy strings","user":{"login":"Yoric","id":10190,"node_id":"MDQ6VXNlcjEwMTkw","avatar_url":"https://avatars1.githubusercontent.com/u/10190?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoric","html_url":"https://github.com/Yoric","followers_url":"https://api.github.com/users/Yoric/followers","following_url":"https://api.github.com/users/Yoric/following{/other_user}","gists_url":"https://api.github.com/users/Yoric/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoric/subscriptions","organizations_url":"https://api.github.com/users/Yoric/orgs","repos_url":"https://api.github.com/users/Yoric/repos","events_url":"https://api.github.com/users/Yoric/events{/privacy}","received_events_url":"https://api.github.com/users/Yoric/received_events","type":"User","site_admin":false},"body":"This time, shorter PR :)","created_at":"2018-11-14T17:16:08Z","updated_at":"2018-11-15T01:54:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1eaf26df875001c9346da9c92fd6d2ab020bdf52","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/binast/binjs-ref/pulls/201/commits","review_comments_url":"https://api.github.com/repos/binast/binjs-ref/pulls/201/comments","review_comment_url":"https://api.github.com/repos/binast/binjs-ref/pulls/comments{/number}","comments_url":"https://api.github.com/repos/binast/binjs-ref/issues/201/comments","statuses_url":"https://api.github.com/repos/binast/binjs-ref/statuses/f2d765dfce73ebf71f0672721704bb4fdf57ce2c","head":{"label":"Yoric:entropy-strings","ref":"entropy-strings","sha":"f2d765dfce73ebf71f0672721704bb4fdf57ce2c","user":{"login":"Yoric","id":10190,"node_id":"MDQ6VXNlcjEwMTkw","avatar_url":"https://avatars1.githubusercontent.com/u/10190?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoric","html_url":"https://github.com/Yoric","followers_url":"https://api.github.com/users/Yoric/followers","following_url":"https://api.github.com/users/Yoric/following{/other_user}","gists_url":"https://api.github.com/users/Yoric/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoric/subscriptions","organizations_url":"https://api.github.com/users/Yoric/orgs","repos_url":"https://api.github.com/users/Yoric/repos","events_url":"https://api.github.com/users/Yoric/events{/privacy}","received_events_url":"https://api.github.com/users/Yoric/received_events","type":"User","site_admin":false},"repo":{"id":151379140,"node_id":"MDEwOlJlcG9zaXRvcnkxNTEzNzkxNDA=","name":"binjs-ref","full_name":"Yoric/binjs-ref","private":false,"owner":{"login":"Yoric","id":10190,"node_id":"MDQ6VXNlcjEwMTkw","avatar_url":"https://avatars1.githubusercontent.com/u/10190?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoric","html_url":"https://github.com/Yoric","followers_url":"https://api.github.com/users/Yoric/followers","following_url":"https://api.github.com/users/Yoric/following{/other_user}","gists_url":"https://api.github.com/users/Yoric/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoric/subscriptions","organizations_url":"https://api.github.com/users/Yoric/orgs","repos_url":"https://api.github.com/users/Yoric/repos","events_url":"https://api.github.com/users/Yoric/events{/privacy}","received_events_url":"https://api.github.com/users/Yoric/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Yoric/binjs-ref","description":"Reference implementation for the JavaScript Binary AST format","fork":true,"url":"https://api.github.com/repos/Yoric/binjs-ref","forks_url":"https://api.github.com/repos/Yoric/binjs-ref/forks","keys_url":"https://api.github.com/repos/Yoric/binjs-ref/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoric/binjs-ref/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoric/binjs-ref/teams","hooks_url":"https://api.github.com/repos/Yoric/binjs-ref/hooks","issue_events_url":"https://api.github.com/repos/Yoric/binjs-ref/issues/events{/number}","events_url":"https://api.github.com/repos/Yoric/binjs-ref/events","assignees_url":"https://api.github.com/repos/Yoric/binjs-ref/assignees{/user}","branches_url":"https://api.github.com/repos/Yoric/binjs-ref/branches{/branch}","tags_url":"https://api.github.com/repos/Yoric/binjs-ref/tags","blobs_url":"https://api.github.com/repos/Yoric/binjs-ref/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoric/binjs-ref/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoric/binjs-ref/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoric/binjs-ref/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoric/binjs-ref/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoric/binjs-ref/languages","stargazers_url":"https://api.github.com/repos/Yoric/binjs-ref/stargazers","contributors_url":"https://api.github.com/repos/Yoric/binjs-ref/contributors","subscribers_url":"https://api.github.com/repos/Yoric/binjs-ref/subscribers","subscription_url":"https://api.github.com/repos/Yoric/binjs-ref/subscription","commits_url":"https://api.github.com/repos/Yoric/binjs-ref/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoric/binjs-ref/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoric/binjs-ref/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoric/binjs-ref/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoric/binjs-ref/contents/{+path}","compare_url":"https://api.github.com/repos/Yoric/binjs-ref/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoric/binjs-ref/merges","archive_url":"https://api.github.com/repos/Yoric/binjs-ref/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoric/binjs-ref/downloads","issues_url":"https://api.github.com/repos/Yoric/binjs-ref/issues{/number}","pulls_url":"https://api.github.com/repos/Yoric/binjs-ref/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoric/binjs-ref/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoric/binjs-ref/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoric/binjs-ref/labels{/name}","releases_url":"https://api.github.com/repos/Yoric/binjs-ref/releases{/id}","deployments_url":"https://api.github.com/repos/Yoric/binjs-ref/deployments","created_at":"2018-10-03T07:56:02Z","updated_at":"2018-10-03T07:56:33Z","pushed_at":"2018-11-14T19:44:22Z","git_url":"git://github.com/Yoric/binjs-ref.git","ssh_url":"git@github.com:Yoric/binjs-ref.git","clone_url":"https://github.com/Yoric/binjs-ref.git","svn_url":"https://github.com/Yoric/binjs-ref","homepage":"https://binast.github.io/binjs-ref/binjs/index.html","size":42388,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"binast:master","ref":"master","sha":"6de03681e67e83908d4e158e5a65b887b8de83b2","user":{"login":"binast","id":34548197,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0NTQ4MTk3","avatar_url":"https://avatars3.githubusercontent.com/u/34548197?v=4","gravatar_id":"","url":"https://api.github.com/users/binast","html_url":"https://github.com/binast","followers_url":"https://api.github.com/users/binast/followers","following_url":"https://api.github.com/users/binast/following{/other_user}","gists_url":"https://api.github.com/users/binast/gists{/gist_id}","starred_url":"https://api.github.com/users/binast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binast/subscriptions","organizations_url":"https://api.github.com/users/binast/orgs","repos_url":"https://api.github.com/users/binast/repos","events_url":"https://api.github.com/users/binast/events{/privacy}","received_events_url":"https://api.github.com/users/binast/received_events","type":"Organization","site_admin":false},"repo":{"id":90141336,"node_id":"MDEwOlJlcG9zaXRvcnk5MDE0MTMzNg==","name":"binjs-ref","full_name":"binast/binjs-ref","private":false,"owner":{"login":"binast","id":34548197,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0NTQ4MTk3","avatar_url":"https://avatars3.githubusercontent.com/u/34548197?v=4","gravatar_id":"","url":"https://api.github.com/users/binast","html_url":"https://github.com/binast","followers_url":"https://api.github.com/users/binast/followers","following_url":"https://api.github.com/users/binast/following{/other_user}","gists_url":"https://api.github.com/users/binast/gists{/gist_id}","starred_url":"https://api.github.com/users/binast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binast/subscriptions","organizations_url":"https://api.github.com/users/binast/orgs","repos_url":"https://api.github.com/users/binast/repos","events_url":"https://api.github.com/users/binast/events{/privacy}","received_events_url":"https://api.github.com/users/binast/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/binast/binjs-ref","description":"Reference implementation for the JavaScript Binary AST format","fork":false,"url":"https://api.github.com/repos/binast/binjs-ref","forks_url":"https://api.github.com/repos/binast/binjs-ref/forks","keys_url":"https://api.github.com/repos/binast/binjs-ref/keys{/key_id}","collaborators_url":"https://api.github.com/repos/binast/binjs-ref/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/binast/binjs-ref/teams","hooks_url":"https://api.github.com/repos/binast/binjs-ref/hooks","issue_events_url":"https://api.github.com/repos/binast/binjs-ref/issues/events{/number}","events_url":"https://api.github.com/repos/binast/binjs-ref/events","assignees_url":"https://api.github.com/repos/binast/binjs-ref/assignees{/user}","branches_url":"https://api.github.com/repos/binast/binjs-ref/branches{/branch}","tags_url":"https://api.github.com/repos/binast/binjs-ref/tags","blobs_url":"https://api.github.com/repos/binast/binjs-ref/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/binast/binjs-ref/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/binast/binjs-ref/git/refs{/sha}","trees_url":"https://api.github.com/repos/binast/binjs-ref/git/trees{/sha}","statuses_url":"https://api.github.com/repos/binast/binjs-ref/statuses/{sha}","languages_url":"https://api.github.com/repos/binast/binjs-ref/languages","stargazers_url":"https://api.github.com/repos/binast/binjs-ref/stargazers","contributors_url":"https://api.github.com/repos/binast/binjs-ref/contributors","subscribers_url":"https://api.github.com/repos/binast/binjs-ref/subscribers","subscription_url":"https://api.github.com/repos/binast/binjs-ref/subscription","commits_url":"https://api.github.com/repos/binast/binjs-ref/commits{/sha}","git_commits_url":"https://api.github.com/repos/binast/binjs-ref/git/commits{/sha}","comments_url":"https://api.github.com/repos/binast/binjs-ref/comments{/number}","issue_comment_url":"https://api.github.com/repos/binast/binjs-ref/issues/comments{/number}","contents_url":"https://api.github.com/repos/binast/binjs-ref/contents/{+path}","compare_url":"https://api.github.com/repos/binast/binjs-ref/compare/{base}...{head}","merges_url":"https://api.github.com/repos/binast/binjs-ref/merges","archive_url":"https://api.github.com/repos/binast/binjs-ref/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/binast/binjs-ref/downloads","issues_url":"https://api.github.com/repos/binast/binjs-ref/issues{/number}","pulls_url":"https://api.github.com/repos/binast/binjs-ref/pulls{/number}","milestones_url":"https://api.github.com/repos/binast/binjs-ref/milestones{/number}","notifications_url":"https://api.github.com/repos/binast/binjs-ref/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/binast/binjs-ref/labels{/name}","releases_url":"https://api.github.com/repos/binast/binjs-ref/releases{/id}","deployments_url":"https://api.github.com/repos/binast/binjs-ref/deployments","created_at":"2017-05-03T11:25:08Z","updated_at":"2018-11-14T19:07:25Z","pushed_at":"2018-11-14T19:44:23Z","git_url":"git://github.com/binast/binjs-ref.git","ssh_url":"git@github.com:binast/binjs-ref.git","clone_url":"https://github.com/binast/binjs-ref.git","svn_url":"https://github.com/binast/binjs-ref","homepage":"https://binast.github.io/binjs-ref/binjs/index.html","size":42383,"stargazers_count":62,"watchers_count":62,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":70,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":16,"open_issues":70,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/201"},"html":{"href":"https://github.com/binast/binjs-ref/pull/201"},"issue":{"href":"https://api.github.com/repos/binast/binjs-ref/issues/201"},"comments":{"href":"https://api.github.com/repos/binast/binjs-ref/issues/201/comments"},"review_comments":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/201/comments"},"review_comment":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/binast/binjs-ref/pulls/201/commits"},"statuses":{"href":"https://api.github.com/repos/binast/binjs-ref/statuses/f2d765dfce73ebf71f0672721704bb4fdf57ce2c"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"arai-a"}}