mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 17:23:15 -05:00
Small strict null checking pass on a few files (#4293)
* fix some null checking * fix various null strict checks * move location fo sql files in json * fix compile and more unused properties * formatting * small formatting changes * readd types * add comments for angular components * formatting * remove any decl
This commit is contained in:
@@ -5,113 +5,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
// --- trie'ish datastructure
|
||||
|
||||
class Node<E> {
|
||||
element?: E;
|
||||
readonly children = new Map<string, Node<E>>();
|
||||
}
|
||||
|
||||
/**
|
||||
* A trie map that allows for fast look up when keys are substrings
|
||||
* to the actual search keys (dir/subdir-problem).
|
||||
*/
|
||||
export class TrieMap<E> {
|
||||
|
||||
static PathSplitter = (s: string) => s.split(/[\\/]/).filter(s => !!s);
|
||||
|
||||
private readonly _splitter: (s: string) => string[];
|
||||
private _root = new Node<E>();
|
||||
|
||||
constructor(splitter: (s: string) => string[] = TrieMap.PathSplitter) {
|
||||
this._splitter = s => splitter(s).filter(s => Boolean(s));
|
||||
}
|
||||
|
||||
insert(path: string, element: E): void {
|
||||
const parts = this._splitter(path);
|
||||
let i = 0;
|
||||
|
||||
// find insertion node
|
||||
let node = this._root;
|
||||
for (; i < parts.length; i++) {
|
||||
let child = node.children.get(parts[i]);
|
||||
if (child) {
|
||||
node = child;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// create new nodes
|
||||
let newNode: Node<E>;
|
||||
for (; i < parts.length; i++) {
|
||||
newNode = new Node<E>();
|
||||
node.children.set(parts[i], newNode);
|
||||
node = newNode;
|
||||
}
|
||||
|
||||
node.element = element;
|
||||
}
|
||||
|
||||
lookUp(path: string): E {
|
||||
const parts = this._splitter(path);
|
||||
|
||||
let { children } = this._root;
|
||||
let node: Node<E>;
|
||||
for (const part of parts) {
|
||||
node = children.get(part);
|
||||
if (!node) {
|
||||
return undefined;
|
||||
}
|
||||
children = node.children;
|
||||
}
|
||||
|
||||
return node.element;
|
||||
}
|
||||
|
||||
findSubstr(path: string): E {
|
||||
const parts = this._splitter(path);
|
||||
|
||||
let lastNode: Node<E>;
|
||||
let { children } = this._root;
|
||||
for (const part of parts) {
|
||||
const node = children.get(part);
|
||||
if (!node) {
|
||||
break;
|
||||
}
|
||||
if (node.element) {
|
||||
lastNode = node;
|
||||
}
|
||||
children = node.children;
|
||||
}
|
||||
|
||||
// return the last matching node
|
||||
// that had an element
|
||||
if (lastNode) {
|
||||
return lastNode.element;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
findSuperstr(path: string): TrieMap<E> {
|
||||
const parts = this._splitter(path);
|
||||
|
||||
let { children } = this._root;
|
||||
let node: Node<E>;
|
||||
for (const part of parts) {
|
||||
node = children.get(part);
|
||||
if (!node) {
|
||||
return undefined;
|
||||
}
|
||||
children = node.children;
|
||||
}
|
||||
|
||||
const result = new TrieMap<E>(this._splitter);
|
||||
result._root = node;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export function toObject<V>(map: Map<string, V>): { [key: string]: V } {
|
||||
if (map) {
|
||||
let rt: { [key: string]: V } = Object.create(null);
|
||||
|
||||
Reference in New Issue
Block a user