File size: 1,082 Bytes
2b7aae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { WeakLRUCache } from 'weak-lru-cache';

import { RegulationSolution, SpartitoMeasure } from '../../src/starry';

const lruCache = new WeakLRUCache();

interface SolutionStore {
	get: (key: string) => Promise<RegulationSolution>;
	set: (key: string, val: RegulationSolution) => Promise<void>;
	batchGet: (keys: string[]) => Promise<RegulationSolution[]>;
}

// 默认store
const DefaultSolutionStore: SolutionStore = {
	async get(key: string) {
		return lruCache.getValue(key) as RegulationSolution;
	},
	async set(key: string, val: RegulationSolution) {
		lruCache.setValue(key, val);
	},
	async batchGet(keys: string[]) {
		return keys.map((key) => lruCache.getValue(key) as RegulationSolution);
	},
};

const enum MeasureStatus {
	Discard = -1,
	Solved = 0,
	Issue = 1,
	Fatal = 2,
}

interface IssueMeasure {
	scoreId: string;
	measureIndex: number;
	measure: SpartitoMeasure;
	status: MeasureStatus;
}

type SaveIssueMeasure = (data: Omit<IssueMeasure, 'scoreId'>) => void;

export { SolutionStore, DefaultSolutionStore, MeasureStatus, IssueMeasure, SaveIssueMeasure };