Skip to content

Commit

Permalink
chore: update queue
Browse files Browse the repository at this point in the history
  • Loading branch information
csrigogogo committed Sep 18, 2024
1 parent 0080cb7 commit 9bee280
Show file tree
Hide file tree
Showing 26 changed files with 137 additions and 31 deletions.
Binary file added bun.lockb
Binary file not shown.
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
"version": "1.0.0",
"description": "js development kit",
"main": "index.js",
"workspaces": [
"packages/*"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode development --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"currency.js": "^2.0.4",
"lozad": "^1.16.0",
"superstruct": "^2.0.2",
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"webpack": "^5.94.0",
Expand Down
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions packages/algo/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ListNode {
constructor(public val: number, public next: ListNode | null = null) {
this.val = val;
this.next = next;
}
}

/**
* @description 链表队列
*/
class LinkedListQueue {
private front : ListNode | null; // 头节点 #front
private rear : ListNode | null; // 尾节点 #rear
private qsize: number = 0;
constructor() {
this.front = null;
this.rear = null;
}

/* 获取队列的长度 */
get size(): number {
return this.qsize;
}

/* 判断队列是否为空 */
isEmpty(): boolean {
return this.size === 0;
}

push(num: number): void {
const node = new ListNode(num);
// 如果队列为空,则令头、尾节点都指向该节点
if (this.isEmpty()) {
this.front = node;
this.rear = node;
} else {
// 如果队列不为空,则将该节点添加到尾节点之后
this.rear.next = node;
this.rear = node;
}
this.qsize++;
}

pop(): number | null {
const num = this.peek();
if (this.isEmpty()) throw new Error('队列为空');
// 删除头节点
this.front = this.front.next;
this.qsize--;
return num;
}

/* 访问队首元素 */
peek(): number {
if (this.isEmpty()) throw new Error('队列为空');
return this.front.val;
}

}


/**
* @description 双向队列
*/
class DoubleEndedQueue {
constructor() {
this.items = [];
}
}

export {
LinkedListQueue,
DoubleEndedQueue
}
File renamed without changes.
17 changes: 13 additions & 4 deletions src/algo/sku/index2.ts → packages/algo/sku/index2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,24 @@ class SKU {
* @description 所有sku值
*/
get attributeCollectionFlat() {
return this.attributeCollections
return this.attributeCollections.reduce((acc, cur) => {
const valueArr = cur.attributeItem.map((item) => {
return item.value
})
acc = acc.concat(valueArr)
return acc
}, [])
}

/**
* @description 获取 SKU 集合字典 , skuId 为键,sku信息为值 (库存, 价格 等)
*/
get skuCollectionsDict() {
return this.skuCollections.reduce((acc, cur) => {
acc[cur.skuId] = cur
return this.skuCollections.reduce<Record<number, { price: null; amountOnSale: number }>>((acc, cur) => {
acc[cur.skuId] = {
price: cur.price,
amountOnSale: cur.amountOnSale,
}
return acc
}, {})
}
Expand Down Expand Up @@ -482,6 +491,6 @@ class SKU {
const sku = new SKU({
skuCollections: testSku
})
console.log(sku.attributeCollection)
console.log(sku.attributeCollections)

export default sku
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/node/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# nodejs 相关utils (需要依赖平台api)
1 change: 1 addition & 0 deletions packages/utils/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 平台无关的 js utils
2 changes: 1 addition & 1 deletion src/web-bom/index.js → packages/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ export function setCookie({
const expires = `; expires=${date.toUTCString()}`;
// 将Cookie设置为顶级域名
document.cookie = `${cookieName}=${cookieValue}; domain=${topLevelDomain}; path=/${expires}`;
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions packages/web/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# js web相关utils (需要依赖平台api)
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions src/algo/queue.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/currency.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { thousandify, generatePriceTemplate } from './thousandify.js';
import { SignalType } from './useSignal.ts';
import * as webBom from './web-bom/index.js';
import springer from './animation/springer.ts';
import sku from './algo/sku/index2.ts';
import * as webBom from '../packages/web/index.js';
import springer from '../packages/animation/springer.js';
import sku from '../packages/algo/sku/index2.js';

export {
thousandify,
Expand Down
10 changes: 10 additions & 0 deletions src/validateData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as s from 'superstruct'

const Email = s.define('Email', (string)=>{

})


export {
s
}
3 changes: 0 additions & 3 deletions src/web-bom/readme.md

This file was deleted.

0 comments on commit 9bee280

Please sign in to comment.