Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js

Issue 2385093002: DevTools: introduce Trie data structure (Closed)
Patch Set: rebaseline Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js
diff --git a/third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js b/third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js
index f7817fb3591804c120fe969812aaf35dd86ba0a0..19a3403dcdff39293642ddeedfb2a64af55e7c77 100644
--- a/third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js
+++ b/third_party/WebKit/Source/devtools/front_end/common/TextDictionary.js
@@ -35,6 +35,7 @@ WebInspector.TextDictionary = function()
{
/** @type {!Map<string, number>} */
this._words = new Map();
+ this._index = new Trie();
}
WebInspector.TextDictionary.prototype = {
@@ -46,6 +47,7 @@ WebInspector.TextDictionary.prototype = {
var count = this._words.get(word) || 0;
++count;
this._words.set(word, count);
+ this._index.add(word);
},
/**
@@ -56,6 +58,7 @@ WebInspector.TextDictionary.prototype = {
var count = this._words.get(word) || 0;
if (!count)
return;
+ this._index.remove(word);
if (count === 1) {
this._words.delete(word);
return;
@@ -70,12 +73,7 @@ WebInspector.TextDictionary.prototype = {
*/
wordsWithPrefix: function(prefix)
{
- var words = [];
- for (var word of this._words.keys()) {
- if (word.startsWith(prefix))
- words.push(word);
- }
- return words;
+ return this._index.words(prefix);
},
/**
@@ -99,5 +97,6 @@ WebInspector.TextDictionary.prototype = {
reset: function()
{
this._words.clear();
+ this._index.clear();
}
}

Powered by Google App Engine
This is Rietveld 408576698