mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
class NoteSet {
|
|
constructor(notes = []) {
|
|
/** @type {Note[]} */
|
|
this.notes = notes;
|
|
this.noteIdSet = new Set(notes.map(note => note.noteId));
|
|
/** @type {boolean} */
|
|
this.sorted = false;
|
|
}
|
|
|
|
add(note) {
|
|
if (!this.hasNote(note)) {
|
|
this.notes.push(note);
|
|
this.noteIdSet.add(note.noteId);
|
|
}
|
|
}
|
|
|
|
addAll(notes) {
|
|
for (const note of notes) {
|
|
this.add(note);
|
|
}
|
|
}
|
|
|
|
hasNote(note) {
|
|
return this.hasNoteId(note.noteId);
|
|
}
|
|
|
|
hasNoteId(noteId) {
|
|
return this.noteIdSet.has(noteId);
|
|
}
|
|
|
|
mergeIn(anotherNoteSet) {
|
|
for (const note of anotherNoteSet.notes) {
|
|
if (!this.noteIdSet.has(note.noteId)) {
|
|
this.noteIdSet.add(note.noteId);
|
|
this.notes.push(note);
|
|
}
|
|
}
|
|
}
|
|
|
|
minus(anotherNoteSet) {
|
|
const newNoteSet = new NoteSet();
|
|
|
|
for (const note of this.notes) {
|
|
if (!anotherNoteSet.hasNoteId(note.noteId)) {
|
|
newNoteSet.add(note);
|
|
}
|
|
}
|
|
|
|
return newNoteSet;
|
|
}
|
|
|
|
intersection(anotherNoteSet) {
|
|
const newNoteSet = new NoteSet();
|
|
|
|
for (const note of this.notes) {
|
|
if (anotherNoteSet.hasNote(note)) {
|
|
newNoteSet.add(note);
|
|
}
|
|
}
|
|
|
|
return newNoteSet;
|
|
}
|
|
}
|
|
|
|
module.exports = NoteSet;
|