mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-11-23 04:29:05 +01:00
Use deque instead of linked list
This commit is contained in:
parent
0702d0974b
commit
bde20a1a65
4 changed files with 6 additions and 37 deletions
|
@ -31,6 +31,7 @@
|
||||||
"@types/dateformat": "1.0.1",
|
"@types/dateformat": "1.0.1",
|
||||||
"@types/debug": "0.0.30",
|
"@types/debug": "0.0.30",
|
||||||
"@types/deep-equal": "1.0.1",
|
"@types/deep-equal": "1.0.1",
|
||||||
|
"@types/double-ended-queue": "2.1.0",
|
||||||
"@types/elasticsearch": "5.0.25",
|
"@types/elasticsearch": "5.0.25",
|
||||||
"@types/file-type": "5.2.1",
|
"@types/file-type": "5.2.1",
|
||||||
"@types/gulp": "3.8.36",
|
"@types/gulp": "3.8.36",
|
||||||
|
@ -97,6 +98,7 @@
|
||||||
"deepcopy": "0.6.3",
|
"deepcopy": "0.6.3",
|
||||||
"diskusage": "0.2.4",
|
"diskusage": "0.2.4",
|
||||||
"dompurify": "1.0.5",
|
"dompurify": "1.0.5",
|
||||||
|
"double-ended-queue": "2.1.0-0",
|
||||||
"elasticsearch": "15.1.1",
|
"elasticsearch": "15.1.1",
|
||||||
"element-ui": "2.4.6",
|
"element-ui": "2.4.6",
|
||||||
"emojilib": "2.3.0",
|
"emojilib": "2.3.0",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
|
import * as Deque from 'double-ended-queue';
|
||||||
import Xev from 'xev';
|
import Xev from 'xev';
|
||||||
import Queue from '../misc/queue';
|
|
||||||
|
|
||||||
const ev = new Xev();
|
const ev = new Xev();
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
const log = new Queue<any>();
|
const log = new Deque<any>();
|
||||||
|
|
||||||
const p = childProcess.fork(__dirname + '/notes-stats-child.js');
|
const p = childProcess.fork(__dirname + '/notes-stats-child.js');
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as sysUtils from 'systeminformation';
|
import * as sysUtils from 'systeminformation';
|
||||||
import * as diskusage from 'diskusage';
|
import * as diskusage from 'diskusage';
|
||||||
|
import * as Deque from 'double-ended-queue';
|
||||||
import Xev from 'xev';
|
import Xev from 'xev';
|
||||||
import Queue from '../misc/queue';
|
|
||||||
const osUtils = require('os-utils');
|
const osUtils = require('os-utils');
|
||||||
|
|
||||||
const ev = new Xev();
|
const ev = new Xev();
|
||||||
|
@ -13,7 +13,7 @@ const interval = 1000;
|
||||||
* Report server stats regularly
|
* Report server stats regularly
|
||||||
*/
|
*/
|
||||||
export default function() {
|
export default function() {
|
||||||
const log = new Queue<any>();
|
const log = new Deque<any>();
|
||||||
|
|
||||||
ev.on('requestServerStatsLog', id => {
|
ev.on('requestServerStatsLog', id => {
|
||||||
ev.emit('serverStatsLog:' + id, log.toArray());
|
ev.emit('serverStatsLog:' + id, log.toArray());
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
type Node<T> = { value: T, next: Node<T> };
|
|
||||||
|
|
||||||
export default class Queue<T> {
|
|
||||||
private top: Node<T> = null;
|
|
||||||
private rear: Node<T> = null;
|
|
||||||
public length: number = 0;
|
|
||||||
|
|
||||||
public push(value: T): void {
|
|
||||||
const node: Node<T> = { value, next: null };
|
|
||||||
if (this.top === null) {
|
|
||||||
this.top = node;
|
|
||||||
this.rear = node;
|
|
||||||
} else {
|
|
||||||
this.rear.next = node;
|
|
||||||
this.rear = node;
|
|
||||||
}
|
|
||||||
this.length++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public pop(): void {
|
|
||||||
this.top = this.top.next;
|
|
||||||
if (this.top == null) this.rear = null;
|
|
||||||
this.length--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public toArray(): T[] {
|
|
||||||
const arr: T[] = Array<T>(this.length);
|
|
||||||
for (let node = this.top, i = 0; node !== null; node = node.next, i++) {
|
|
||||||
arr[i] = node.value;
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue