mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
refactor: IC 池重命名为属性池
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#![doc = "OxideJS - Shared kernel (CodeForge, ShapeForge, IcForge, StringForge, BuiltinWorld)"]
|
||||
|
||||
pub mod code_forge;
|
||||
pub mod ic_forge;
|
||||
pub mod prop_forge;
|
||||
pub mod shape_forge;
|
||||
pub mod string_forge;
|
||||
|
||||
@@ -5,32 +5,32 @@ use dashmap::DashMap;
|
||||
use crate::shape_forge::ShapeId;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IcTemplate {
|
||||
pub struct PropTemplate {
|
||||
pub shape_id: ShapeId,
|
||||
pub offset: u8,
|
||||
pub generation: u32,
|
||||
}
|
||||
|
||||
pub struct IcForge {
|
||||
templates: DashMap<ShapeId, Arc<IcTemplate>>,
|
||||
pub struct PropForge {
|
||||
templates: DashMap<ShapeId, Arc<PropTemplate>>,
|
||||
}
|
||||
|
||||
impl IcForge {
|
||||
impl PropForge {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
templates: DashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_template(&self, shape_id: ShapeId) -> Option<Arc<IcTemplate>> {
|
||||
pub fn get_template(&self, shape_id: ShapeId) -> Option<Arc<PropTemplate>> {
|
||||
self.templates.get(&shape_id).map(|r| Arc::clone(&*r))
|
||||
}
|
||||
|
||||
pub fn upsert(&self, shape_id: ShapeId, template: IcTemplate) {
|
||||
pub fn upsert(&self, shape_id: ShapeId, template: PropTemplate) {
|
||||
self.templates.insert(shape_id, Arc::new(template));
|
||||
}
|
||||
|
||||
pub fn upsert_if_better(&self, shape_id: ShapeId, template: IcTemplate) {
|
||||
pub fn upsert_if_better(&self, shape_id: ShapeId, template: PropTemplate) {
|
||||
use dashmap::mapref::entry::Entry;
|
||||
|
||||
match self.templates.entry(shape_id) {
|
||||
@@ -46,7 +46,7 @@ impl IcForge {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IcForge {
|
||||
impl Default for PropForge {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
@@ -58,14 +58,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_nonexistent() {
|
||||
let forge = IcForge::new();
|
||||
let forge = PropForge::new();
|
||||
assert!(forge.get_template(999).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_upsert_and_get() {
|
||||
let forge = IcForge::new();
|
||||
let t = IcTemplate {
|
||||
let forge = PropForge::new();
|
||||
let t = PropTemplate {
|
||||
shape_id: 1,
|
||||
offset: 3,
|
||||
generation: 10,
|
||||
@@ -79,10 +79,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_upsert_if_better_high_gen_wins() {
|
||||
let forge = IcForge::new();
|
||||
let forge = PropForge::new();
|
||||
forge.upsert_if_better(
|
||||
1,
|
||||
IcTemplate {
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
offset: 3,
|
||||
generation: 10,
|
||||
@@ -90,7 +90,7 @@ mod tests {
|
||||
);
|
||||
forge.upsert_if_better(
|
||||
1,
|
||||
IcTemplate {
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
offset: 7,
|
||||
generation: 5,
|
||||
@@ -102,10 +102,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_upsert_if_better_low_replaced() {
|
||||
let forge = IcForge::new();
|
||||
let forge = PropForge::new();
|
||||
forge.upsert_if_better(
|
||||
1,
|
||||
IcTemplate {
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
offset: 3,
|
||||
generation: 5,
|
||||
@@ -113,7 +113,7 @@ mod tests {
|
||||
);
|
||||
forge.upsert_if_better(
|
||||
1,
|
||||
IcTemplate {
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
offset: 7,
|
||||
generation: 10,
|
||||
Reference in New Issue
Block a user