data-footstone
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -11,2 +11,3 @@ import arrayTool from './lib/arrayTool.js' | ||
import orderTool from './lib/orderTool.js' | ||
import baseTool from './lib/baseTool.js' | ||
@@ -23,3 +24,6 @@ export default { | ||
treeTool, | ||
orderTool | ||
orderTool, | ||
baseTool: { | ||
Lru: baseTool.Lru | ||
} | ||
} |
// 基本的、常用的、杂乱的方法 | ||
import {DoublyLinkedList} from './linkedListTool.js' | ||
import {HashTableLinked} from './hashTable.js' | ||
/** | ||
@@ -403,2 +407,43 @@ * 是否为奇数 | ||
// least recently used | ||
class Lru { | ||
constructor (capacity) { | ||
this.capacity = capacity | ||
this.map = new HashTableLinked() | ||
this.doublyLinkedList = new DoublyLinkedList() | ||
} | ||
// 添加一个键值对 | ||
put (key, value) { | ||
if (this.doublyLinkedList.size() >= this.capacity) { // 已满 | ||
let obsolet = this.doublyLinkedList.getTail() | ||
this.map.remove(obsolet) | ||
this.doublyLinkedList.removeTail() | ||
} | ||
this.map.put(key, value) | ||
this.doublyLinkedList.insert(0, key) | ||
} | ||
// 获取一个值 | ||
get (key) { | ||
this.moveToHeadByPosition(Math.max(0, this.doublyLinkedList.getPositionByElement(key))) | ||
return this.map.get(key) | ||
} | ||
// 把节点移到头部 | ||
moveToHeadByPosition (position) { | ||
this.doublyLinkedList.moveToHeadByPosition(position) | ||
} | ||
// 清空lru | ||
clear () { | ||
this.map.clear() | ||
this.doublyLinkedList.clear() | ||
} | ||
// 获取当前缓存了多少个数据 | ||
size () { | ||
return this.doublyLinkedList.size() | ||
} | ||
remove (key) { | ||
this.map.remove(key) | ||
this.doublyLinkedList.removeElement(key) | ||
} | ||
} | ||
export default { | ||
@@ -428,3 +473,4 @@ searchStrToObj, | ||
searchStrToObj, | ||
setExtend | ||
setExtend, | ||
Lru | ||
} |
@@ -53,4 +53,4 @@ // 哈希表相关的方法 | ||
} | ||
remove () { | ||
let position = this.loseloseHashCode(key) | ||
remove (key) { | ||
let position = this.djbHashCode(key) | ||
let link = this.table[position] | ||
@@ -92,2 +92,5 @@ if (link.isEmpty()) { | ||
} | ||
clear () { | ||
this.table = {} | ||
} | ||
} | ||
@@ -133,2 +136,5 @@ | ||
} | ||
clear () { | ||
this.table = {} | ||
} | ||
} | ||
@@ -135,0 +141,0 @@ |
@@ -36,3 +36,3 @@ // 链表相关的工具方法 | ||
super() | ||
this.length = 0 | ||
// this.length = 0 | ||
if (iterate.length) { | ||
@@ -48,4 +48,4 @@ let link = iterate.reduceRight((res, cur) => { | ||
this.head = link | ||
} else { | ||
this.head = null | ||
// } else { | ||
// this.head = null | ||
} | ||
@@ -222,2 +222,7 @@ } | ||
rehead () {} | ||
clear () { | ||
this.head = null | ||
this.length = 0 | ||
return this.size() | ||
} | ||
} | ||
@@ -227,6 +232,7 @@ /* | ||
*/ | ||
class DoublyLinkedList { | ||
class DoublyLinkedList extends LinkBase { | ||
constructor () { | ||
this.head = null | ||
this.length = 0 | ||
super() | ||
// this.head = null | ||
// this.length = 0 | ||
this.tail = null | ||
@@ -254,9 +260,59 @@ } | ||
} | ||
// 根据位置得到元素 | ||
getElementByPostion (position) { | ||
let res = null | ||
if (position >= 0) { | ||
if (position < this.length) { | ||
let index = 0 | ||
let cur = this.head // , prev | ||
while (index++ < position) { | ||
// prev = cur | ||
cur = cur.next | ||
} | ||
// return cur.element | ||
res = cur.element | ||
} | ||
} else { | ||
if (Math.abs(position) <= this.length) { | ||
let index = -1, cur = this.tail | ||
while (index-- > position) { | ||
cur = cur.prev | ||
} | ||
res = cur.element | ||
} | ||
} | ||
return res | ||
} | ||
// 根据元素得到第一个符合元素的位置 | ||
getPositionByElement (element) { | ||
let cur = this.head, flag = false, position = -1 | ||
while (cur && !flag) { | ||
if (cur.element === element) { | ||
flag = !flag | ||
} else { | ||
cur = cur.next | ||
} | ||
position++ | ||
} | ||
return !flag ? -1 : position | ||
} | ||
// 是否存在指定element | ||
existElement (element) { | ||
let cur = this.head | ||
let flag = true | ||
while (flag && cur) { | ||
if (cur.element === element) { | ||
flag = false | ||
} else { | ||
cur = cur.next | ||
} | ||
} | ||
return !flag | ||
} | ||
// 在指定位置插入 | ||
// 返回boolean,表示插入成功、失败。 | ||
insert (position, element) { | ||
if (position > 0 && position <= this.length) { | ||
if (position >= 0 && position <= this.length) { | ||
let node = DoublyLinkedList.node(element), current, previous, index = 0 | ||
if (position === 0) { // head | ||
// node.next = this.head | ||
// this.head = node | ||
if (this.length) { | ||
@@ -293,3 +349,5 @@ node.next = this.head | ||
} | ||
// 删除指定位置的节点,若删除成功则返回节点的element。否则返回false | ||
// 从head边开始查询并删除指定位置的节点 | ||
// position >= 0 | ||
// 返回操作后的链表长度 | ||
removeAt (position) { | ||
@@ -308,3 +366,2 @@ if (position > -1 && position < this.length) { | ||
if (position === this.length - 1) { // tail | ||
// if (this.length) {} | ||
current = this.tail | ||
@@ -323,7 +380,57 @@ this.tail = current.prev | ||
this.length-- | ||
return current.element | ||
} | ||
return this.size() | ||
} | ||
// 从tail开始查询并删除指定位置的节点 | ||
// position < 0 | ||
// 返回链表长度 | ||
removeAtRight (position) { | ||
if (position < 0 && Math.abs(position) <= this.length ) { | ||
if (position === -1) { | ||
this.removeTail() | ||
} else if (Math.abs(position) === this.length) { | ||
this.removeHead() | ||
} else { | ||
let cur = this.tail.next, post = this.tail, index = -1 | ||
while (index-- > position) { | ||
post = cur | ||
cur = cur.prev | ||
} | ||
cur.prev.next = post | ||
post.prev = cur.prev | ||
} | ||
} | ||
return this.size() | ||
} | ||
// 删除最后一个元素 | ||
// 不返回东西 | ||
removeTail () { | ||
if (this.length === 1) { | ||
this.head = null | ||
this.tail = null | ||
this.length-- | ||
} else { | ||
return false | ||
if (this.length > 1) { | ||
this.tail = this.tail.prev | ||
this.tail.next = null | ||
this.length-- | ||
} | ||
} | ||
return this.size() | ||
} | ||
// 删除第一个元素 | ||
removeHead () { | ||
if (this.length === 1) { | ||
this.head = null | ||
this.tail = null | ||
this.length-- | ||
} else { | ||
if (this.length > 1) { | ||
this.head = this.head.next | ||
this.head.prev = null | ||
this.length-- | ||
} | ||
} | ||
return this.size() | ||
} | ||
// 删除指定元素 | ||
@@ -358,6 +465,5 @@ removeElement (element, all = false) { | ||
} | ||
// removeElementAll () {} | ||
// 连接成字符串 | ||
join (separate = '') { | ||
let current = this.head, res = '' | ||
let current = this.head, str = '' | ||
while (current) { | ||
@@ -369,53 +475,158 @@ str += String(current.element) + separate | ||
} | ||
// 切片后的链条 | ||
// slice(start = 0, end = this.length - 1) { | ||
// if (start > 0 && start < this.length - 1 && end >= start && end <= this.length - 1) { | ||
// let current = this.head, index = 0 | ||
// while (index < start) { | ||
// current = current.next | ||
// index++ | ||
// } | ||
// this.head = current | ||
// this.head.prev = null | ||
// while (index < end) { | ||
// current = current.next | ||
// index++ | ||
// } | ||
// this.tail = current | ||
// this.tail.next = null | ||
// } | ||
// let index = 0, current = this.head | ||
// while (current) { | ||
// current = current.next | ||
// index++ | ||
// } | ||
// this.length = index | ||
// return this | ||
// } | ||
// 应改为不改变原链表,返回新链表。 | ||
slice (start = 0, end = this.length - 1) { | ||
// 不改变原链表,返回新链表。 | ||
slice (start = 0, end = this.length) { | ||
let link = new DoublyLinkedList() | ||
for (let i = 0, iLen = end - start; i < iLen; i++) { | ||
link.append(this.getEleByIndex(i)) | ||
end = (this.length < end) ? this.length : end | ||
end = end < 0 ? (this.length + end) : end | ||
if (0 <= start && start <= end && end <= this.length) { | ||
let len = end - start | ||
let index = 0 | ||
let cur = this.head | ||
while (index++ < start) { | ||
cur = cur.next | ||
} | ||
index = 0 | ||
while (index++ < len) { | ||
link.append(cur.element) | ||
cur = cur.next | ||
} | ||
} | ||
return link | ||
} | ||
// 获取指定位置的元素 | ||
getEleByIndex (position) { | ||
if (position > 0 && position < this.length) { | ||
let index = 0, current = this.head | ||
while (index++ < position) { | ||
current = current.next | ||
// 把指定部分的元素设置为replcement。 | ||
// 返回被删除的新元素。 | ||
splice (start = 0, len = 0, ...replacement) { | ||
let res = [] | ||
if (0 <= start && start <= this.length) { | ||
len = len < 0 ? 0 : len | ||
len = Math.min(this.length - start, len) | ||
// 取被删除的数据 | ||
res = this.slice(start, start + len).toArray() | ||
if (start === 0) { // start | ||
let flag = this.head | ||
let index = 0 | ||
while (index++ < len) { | ||
flag = flag.next | ||
} | ||
let temp = new DoublyLinkedList() | ||
for (let i = 0; i < replacement.length; i++) { | ||
temp.append(replacement[i]) | ||
} | ||
temp.tail.next = flag // this.head | ||
this.head = temp.head | ||
this.length -= len | ||
this.length += replacement.length | ||
temp = null | ||
} else if (start === this.length) { // tail | ||
for (let i = 0; i < replacement.length; i++) { | ||
this.append(replacement[i]) | ||
} | ||
} else { // middle | ||
if (this.length <= (start + len)) { // 去掉start后面的全部。 | ||
let flag = this.head | ||
let index = 0 | ||
while (index++ < start) { | ||
flag = flag.next | ||
} | ||
this.tail = flag | ||
for (let i = 0; i < replacement.length; i++) { | ||
this.append(replacement[i]) | ||
} | ||
this.length = index + replacement.length | ||
} else { // 去掉中间部分 | ||
let index = 0 | ||
let prev = this.head | ||
while (index++ < start) { | ||
prev = prev.next | ||
} | ||
let post = prev.next | ||
while (index++ <= start + len) { | ||
post = post.next | ||
} | ||
let temp = new DoublyLinkedList() | ||
for (let i = 0; i < replacement.length; i++) { | ||
temp.append(replacement[i]) | ||
} | ||
temp.tail.next = post | ||
post.prev = temp.tail | ||
temp.head.prev = prev | ||
prev.next = temp.head | ||
temp = null | ||
this.length -= len | ||
this.length += replacement.length | ||
} | ||
} | ||
return current.element | ||
} | ||
return res | ||
} | ||
// 获取头节点 | ||
// 把element转换为数组 | ||
toArray () { | ||
let cur = this.head | ||
let arr = [] | ||
while (cur) { | ||
arr.push(cur.element) | ||
cur = cur.next | ||
} | ||
return arr | ||
} | ||
// 获取头节点的元素 | ||
getHead () { | ||
return this.head | ||
return this.head.element | ||
} | ||
// 获取尾节点 | ||
// 获取尾节点的元素 | ||
getTail () { | ||
return this.tail | ||
return this.tail.element | ||
} | ||
moveToHeadByElement () { | ||
// 可能用不到 | ||
} | ||
// 把指定位置的节点移动到头部。不返回东西 | ||
moveToHeadByPosition (position) { | ||
let cur = this.head | ||
if (position > 0) { | ||
if (position < this.length) { | ||
if (position === this.length - 1) { | ||
let cur = this.tail | ||
this.tail = this.tail.prev | ||
this.tail.next = null | ||
cur.next = this.head | ||
cur.prev = null | ||
this.head = cur | ||
} else { | ||
let cur = this.head, index = 0 | ||
while (index++ < position) { | ||
cur = cur.next | ||
} | ||
cur.prev.next = cur.next | ||
cur.next.prev = cur.prev | ||
cur.next = this.head | ||
cur.prev = null | ||
this.head.prev = cur | ||
this.head = cur | ||
} | ||
} | ||
} else if (position < 0) { | ||
if (Math.abs(position) < this.length) { | ||
if (position === -1) { | ||
let cur = this.tail | ||
this.tail = this.tail.prev | ||
this.tail.next = null | ||
cur.next = this.head | ||
cur.prev = null | ||
this.head = cur | ||
} else { | ||
let cur = this.tail, index = -1 | ||
while (index-- > position) { | ||
cur = cur.prev | ||
} | ||
cur.prev.next = cur.next | ||
cur.next.prev = cur.prev | ||
cur.next = this.head | ||
cur.prev = null | ||
this.head.prev = cur | ||
this.head = cur | ||
} | ||
} | ||
} | ||
} | ||
// 是否是空链表 | ||
@@ -425,8 +636,15 @@ isEmpty () { | ||
} | ||
// 清空链表。 | ||
// 返回链表长度。 | ||
clear () { | ||
this.head = null | ||
this.tail = null | ||
this.length = 0 | ||
return this.size() | ||
} | ||
} | ||
/* | ||
循环链表 | ||
*/ | ||
// 需要测试 | ||
class CircularLinkedList extends LinkBase { | ||
@@ -433,0 +651,0 @@ constructor () { |
@@ -61,3 +61,3 @@ // 与树相关的工具方法 | ||
// 获取最小键 | ||
findMinKey (key) { | ||
findMinKey (key = this.root) { | ||
while (key && key.left) { | ||
@@ -69,3 +69,3 @@ key = key.left | ||
// 获取最大键 | ||
findMaxKey (key) { | ||
findMaxKey (key = this.root) { | ||
while (key && key.right) { | ||
@@ -177,3 +177,3 @@ key = key.right | ||
// | ||
// 红黑树 | ||
// http://goo.gl/OxED8K | ||
@@ -180,0 +180,0 @@ class RBTree {} |
{ | ||
"name": "data-footstone", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "基本的数据结构。", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
174
readme.md
@@ -6,10 +6,10 @@ # describe | ||
- Stack | ||
Queue | ||
LinkedList | ||
HashTable | ||
Tree | ||
Graph | ||
- Queue | ||
- LinkedList | ||
- HashTable | ||
- Tree | ||
- Graph | ||
当前版本支持es6规范。即使用export/import方式去抛出、引入。 | ||
暂时不支持commonjs规范。(未来会开发) | ||
当前版本支持es6规范。即使用export/import方式去抛出、引入。 | ||
暂时不支持commonjs规范。即nodejs不能使用。(未来会开发) | ||
@@ -29,10 +29,10 @@ # install | ||
stack.push(1, 2, 3, 4) | ||
console.log(stack.getArray()) | ||
console.log(stack.getArray()) // [1, 2, 3, 4] | ||
stack.pop() | ||
console.log(stack.getArray()) | ||
console.log(stack.getArray()) // [1, 2, 3] | ||
stack.pop() | ||
console.log(stack.getArray()) | ||
console.log(stack.getArray()) // [1, 2] | ||
stack.pop() | ||
console.log(stack.getArray()) | ||
console.log(stack.isEmpty()) | ||
console.log(stack.getArray()) // [1] | ||
console.log(stack.isEmpty()) // false | ||
``` | ||
@@ -48,2 +48,3 @@ ``` | ||
treeTool, | ||
baseTool | ||
} from 'data-footstone' | ||
@@ -87,19 +88,10 @@ | ||
} | ||
baseTool: { | ||
Lru | ||
} | ||
``` | ||
## Graph | ||
var graph = new Graph() | ||
graph.addVertex(v) // 添加顶点 | ||
graph.addEdge(v, w) // 添加边 | ||
graph.toString() // 打印出邻接表 | ||
graph.neighborsMatrix() // 返回邻接矩阵 | ||
graph.neighborsTable() // 返回邻接表 | ||
graph.bfs(v, cb) // 以广度优先方式,依次处理执行cb. | ||
graph.dfs() // 深度优先 | ||
graph.dfsCb(cb) // 以深度优先方式,依次处理执行cb. | ||
## hashTableBase | ||
基本的散列表。使用loseloseHashCode方式散列。 | ||
基本的散列表。使用loseloseHashCode方式散列。 | ||
该散列表不能解决散列冲突。出现散列冲突的可能性比较高。 | ||
@@ -110,4 +102,4 @@ | ||
hashTableBase.put(key, value) // 添加key-value | ||
hashTableBase.remove(key) // 删除key | ||
hashTableBase.get(key) // 获取key对应的value | ||
hashTableBase.remove(key) // 删除key | ||
hashTableBase.get(key) // 获取key对应的value | ||
``` | ||
@@ -117,3 +109,3 @@ | ||
该哈希表使用djbHashCode方式散列。 | ||
该哈希表使用djbHashCode方式散列。 | ||
使用分离链接方法处理哈希冲突。 | ||
@@ -124,4 +116,5 @@ | ||
hashTableLinked.put(key, value) // 添加key-value | ||
hashTableLinked.remove(key) // 删除key | ||
hashTableLinked.get(key) // 获取key对应的value | ||
hashTableLinked.remove(key) // 删除key | ||
hashTableLinked.get(key) // 获取key对应的value | ||
hashTableLinear.clear() // 清空hash表 | ||
``` | ||
@@ -137,4 +130,5 @@ | ||
hashTableLinear.put(key, value) // 添加key-value | ||
hashTableLinear.remove(key) // 删除key | ||
hashTableLinear.get(key) // 获取key对应的value | ||
hashTableLinear.remove(key) // 删除key | ||
hashTableLinear.get(key) // 获取key对应的value | ||
hashTableLinear.clear() // 清空hash表 | ||
``` | ||
@@ -145,3 +139,3 @@ | ||
``` | ||
let linkedList = new LinkedList() | ||
let linkedList = new LinkedList(arr) // 以arr里的元素创建链表 | ||
linkedList.append(element) // 在末尾添加元素 | ||
@@ -165,37 +159,28 @@ linkedList.insert(position, element) // 在position插入元素,position后面的元素依次向后移动。 | ||
doublyLinkedList.append(element) // 在末尾添加元素 | ||
doublyLinkedList.insert(position, element) // 在position插入元素,position后面的元素依次向后移动。 | ||
doublyLinkedList.removeAt(position) // 删除指定位置的节点,若删除成功则返回节点的element。否则返回false | ||
doublyLinkedList.getElementByPostion(position) // 根据位置得到元素 | ||
doublyLinkedList.getPositionByElement(position) // 根据元素得到第一个符合元素的位置 | ||
doublyLinkedList.existElement(element) // 是否存在指定element | ||
doublyLinkedList.insert(position, element) // 在position插入元素。返回boolean,表示插入成功、失败。 | ||
doublyLinkedList.removeAt(position) // 从head边开始查询并删除指定位置的节点。返回操作后的链表长度。position >= 0 | ||
doublyLinkedList.removeAtRight(position) // 从tail开始查询并删除指定位置的节点。返回链表长度。position < 0 | ||
doublyLinkedList.removeTail(position) // 删除最后一个元素不返回东西 | ||
doublyLinkedList.removeHead(position) // 删除第一个元素不返回东西 | ||
doublyLinkedList.removeElement(element, all = false) // 删除指定元素。当all为false,则删除第一个指定的元素,否则删除所有指定的元素。 | ||
doublyLinkedList.join(separate = '') // 把链表中的元素以连接字符串连接起来并返回。 | ||
doublyLinkedList.slice(start = 0, end = this.length - 1) // 切片后的链条。不改变原链表,返回新链表。 | ||
doublyLinkedList.getEleByIndex(position) // 获取指定位置的元素 | ||
doublyLinkedList.getHead(index) // 获取头节点 | ||
doublyLinkedList.splice(start = 0, end = 0, ...replacement) // 切片后的链条。不改变原链表,返回新链表。 | ||
doublyLinkedList.toArray() // 把element转换为数组 | ||
doublyLinkedList.getHead() // 获取头节点 | ||
doublyLinkedList.getTail() // 获取尾节点 | ||
doublyLinkedList.moveToHeadByPosition(position) // 把指定位置的节点移动到头部 | ||
doublyLinkedList.isEmpty() // 是否是空链表 | ||
doublyLinkedList.clear() // 清空链表 | ||
``` | ||
## CircularLinkedList | ||
循环链表 | ||
``` | ||
let circularLinkedList = new CircularLinkedList() | ||
circularLinkedList.append(element) // 在末尾添加元素 | ||
circularLinkedList.insert(position, element) // 在position插入元素,position后面的元素依次向后移动。 | ||
circularLinkedList.removeAt(position) // 删除指定位置的节点,若删除成功则返回节点的element。否则返回false | ||
circularLinkedList.removeElement(element, all = false) // 删除指定元素。当all为false,则删除第一个指定的元素,否则删除所有指定的元素。 | ||
circularLinkedList.join(separate = '') // 把链表中的元素以连接字符串连接起来并返回。 | ||
circularLinkedList.slice(start = 0, end = this.length - 1) // 切片后的链条。不改变原链表,返回新链表。 | ||
circularLinkedList.getEleByIndex(position) // 获取指定位置的元素 | ||
circularLinkedList.getHead(index) // 获取头节点 | ||
circularLinkedList.getTail() // 获取尾节点 | ||
circularLinkedList.isEmpty() // 是否是空链表 | ||
``` | ||
## orderPromise | ||
orderPromise(pArr) | ||
pArr promise对象组成的数组。 | ||
依次请求arr里的promise. | ||
返回各promise的then结果组成的要数组。 | ||
orderPromise(pArr) | ||
pArr promise对象组成的数组。 | ||
依次请求arr里的promise. | ||
返回各promise的then结果组成的要数组。 | ||
返回一个promise对象。其then方法的参数是各promise的then结果组成的要数组。 | ||
@@ -205,7 +190,7 @@ | ||
limitPromise(arr, handler, limit) | ||
arr需要操作的数据 array型 | ||
handler对arr中的数据执行的方法。 function型 | ||
limit最大“并发”量 number型 | ||
限制并发请求的的最大值。 | ||
limitPromise(arr, handler, limit) | ||
arr需要操作的数据 array型 | ||
handler对arr中的数据执行的方法。 function型 | ||
limit最大“并发”量 number型 | ||
限制并发请求的的最大值。 | ||
返回promise对象。其then方法的参数是全部handler的结果。 | ||
@@ -265,13 +250,52 @@ | ||
let binarySearchTree = new BinarySearchTree() | ||
binarySearchTree.insert() // 插入键。返回是否插入成功。 | ||
binarySearchTree.exist() // 是否存在指定的value的key | ||
binarySearchTree.findMinKey() // 获取最小键 | ||
binarySearchTree.findMaxKey() // 获取最大键 | ||
binarySearchTree.removeKey() // 删除第一个key的value = value的key | ||
binarySearchTree.remove() // 删除指定value的key | ||
binarySearchTree.min() // 获取最小的value | ||
binarySearchTree.max() // 获取最大的value | ||
binarySearchTree.inOrderTranverse() // 以中序优先方式,依次使用cb处理各键。 | ||
binarySearchTree.preOrderTranverse() // 以先序优先方式,依次使用cb处理各键。 | ||
binarySearchTree.postOrderTranverse() // 以后序优先方式,依次使用cb处理各键。 | ||
binarySearchTree.insert(key, value) // 插入键。返回是否插入成功。 | ||
binarySearchTree.exist(key) // 是否存在指定的value的key | ||
binarySearchTree.findMinKey(key = this.root) // 获取最小键 | ||
binarySearchTree.findMaxKey(key = this.root) // 获取最大键 | ||
binarySearchTree.remove(value) // 删除指定value的key | ||
binarySearchTree.min() // 获取最小的value | ||
binarySearchTree.max() // 获取最大的value | ||
binarySearchTree.inOrderTranverse(cb) // 以中序优先方式,依次使用cb处理各键。 | ||
binarySearchTree.preOrderTranverse(cb) // 以先序优先方式,依次使用cb处理各键。 | ||
binarySearchTree.postOrderTranverse(cb) // 以后序优先方式,依次使用cb处理各键。 | ||
``` | ||
## Graph | ||
无向图、未加权、强连接。(图的东西太多了,未来扩展吧。) | ||
``` | ||
var graph = new Graph() | ||
graph.addVertex(v) // 添加顶点 | ||
graph.addEdge(v, w) // 添加边 | ||
graph.toString() // 打印出邻接表 | ||
graph.neighborsMatrix() // 返回邻接矩阵 | ||
graph.neighborsTable() // 返回邻接表 | ||
graph.bfs(v, cb) // 以广度优先方式,依次处理执行cb. | ||
graph.dfs() // 深度优先 | ||
graph.dfsCb(cb) // 以深度优先方式,依次处理执行cb. | ||
``` | ||
## Lru | ||
least recently used 最近最少使用 | ||
``` | ||
var lru = new Lru(capacity) | ||
lru.put(key, value) // 添加一个键值对 | ||
lru.get(key) // 获取一个值 | ||
lru.clear() // 清空lru | ||
lru.size() // 获取当前缓存了多少个数据 | ||
lru.remove(key) // 删除指定数据 | ||
``` | ||
# 未来可能添加的 | ||
- Memo 备忘录 | ||
- deepClone | ||
- deepCloneByChannel | ||
- debounce | ||
- throttle | ||
- getType | ||
- plainArr | ||
- CircularLinkedList |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68773
15
2398
289