Merge remote-tracking branch 'origin/repository'

# Conflicts:
#	src/data/entities.rs
This commit is contained in:
micialware committed 2026-08-30 19:25:38 +03:00
commit 18aa748451
8 files changed
+1085 -13

No files matched your search

+87
View File
@@ -3,10 +3,14 @@ use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, OrderMode, WordOpenMode};
use crate::data::{INVALID_ID, Id};
use chrono::{DateTime, NaiveDate, Utc};
use fsrs::MemoryState;
use crate::notification::MaybeError;
use chrono::{DateTime, Utc};
use log::info;
use rayon::prelude::*;
use rhai::{Engine, Scope};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::time::Instant;
#[derive(Clone, Debug)]
@@ -18,6 +22,17 @@ pub struct WordData {
pub additional: HashMap<String, String>,
pub group_id: Id,
}
impl EntityData for WordData {
fn id(&self) -> Id {
self.id
}
fn set_id(&mut self, id: Id) {
self.id = id;
}
}
#[derive(Clone)]
pub struct WordGroup {
pub id: Id,
@@ -168,3 +183,75 @@ impl CardStatistics {
(self.score as f32 * multiplier).max(1.0)
}
}
#[derive(Copy)]
pub struct EntityHandle<E> {
pub(crate) id: Id,
index: i32,
pub(crate) _phantom: PhantomData<E>,
}
impl<T> Clone for EntityHandle<T> {
fn clone(&self) -> Self {
EntityHandle {
id: self.id,
index: self.index,
_phantom: Default::default(),
}
}
}
impl<T> EntityHandle<T> {
pub fn new(id: Id, index: usize, real: bool) -> Self {
Self {
id,
index: index as i32 | (!real as i32) << 31,
_phantom: Default::default(),
}
}
pub fn index(&self) -> usize {
(self.index << 1 >> 1) as usize
}
pub fn set_index(&mut self, index: usize) {
self.index = self.index >> 31 << 31 | index as i32;
}
pub fn real(&self) -> bool {
(self.index >> 31) == 0
}
pub fn set_real(&mut self, value: bool) {
self.index = self.index << 1 >> 1 | (!value as i32) << 31;
}
}
impl<T> Eq for EntityHandle<T> {}
impl<T> PartialEq<Self> for EntityHandle<T> {
fn eq(&self, other: &Self) -> bool {
self.real() == other.real() && self.id == other.id
}
}
impl<T> PartialOrd<Self> for EntityHandle<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<T> Ord for EntityHandle<T> {
fn cmp(&self, other: &Self) -> Ordering {
if self.real() && !other.real() {
return Ordering::Less;
}
if !self.real() && other.real() {
return Ordering::Greater;
}
self.id.cmp(&other.id)
}
}
pub trait EntityData {
fn id(&self) -> Id;
fn set_id(&mut self, id: Id);
}