fix: 修复数组长度与槽位索引截断问题
This commit is contained in:
@@ -7,7 +7,8 @@ use crate::shape_forge::ShapeId;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PropTemplate {
|
||||
pub shape_id: ShapeId,
|
||||
pub position: u8,
|
||||
pub prop_name: u32,
|
||||
pub position: u32,
|
||||
pub generation: u32,
|
||||
}
|
||||
|
||||
@@ -67,12 +68,14 @@ mod tests {
|
||||
let forge = PropForge::new();
|
||||
let t = PropTemplate {
|
||||
shape_id: 1,
|
||||
prop_name: 11,
|
||||
position: 3,
|
||||
generation: 10,
|
||||
};
|
||||
forge.upsert(1, t);
|
||||
let got = forge.get_template(1).unwrap();
|
||||
assert_eq!(got.shape_id, 1);
|
||||
assert_eq!(got.prop_name, 11);
|
||||
assert_eq!(got.position, 3);
|
||||
assert_eq!(got.generation, 10);
|
||||
}
|
||||
@@ -84,6 +87,7 @@ mod tests {
|
||||
1,
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
prop_name: 11,
|
||||
position: 3,
|
||||
generation: 10,
|
||||
},
|
||||
@@ -92,6 +96,7 @@ mod tests {
|
||||
1,
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
prop_name: 12,
|
||||
position: 7,
|
||||
generation: 5,
|
||||
},
|
||||
@@ -107,6 +112,7 @@ mod tests {
|
||||
1,
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
prop_name: 11,
|
||||
position: 3,
|
||||
generation: 5,
|
||||
},
|
||||
@@ -115,6 +121,7 @@ mod tests {
|
||||
1,
|
||||
PropTemplate {
|
||||
shape_id: 1,
|
||||
prop_name: 12,
|
||||
position: 7,
|
||||
generation: 10,
|
||||
},
|
||||
|
||||
@@ -46,8 +46,8 @@ impl ShapeForge {
|
||||
((parent_id as u64) << 32) | (prop_name as u64)
|
||||
}
|
||||
|
||||
fn compute_depth(shape_id: ShapeId, shapes: &[Option<Arc<Shape>>]) -> u8 {
|
||||
let mut count = 0u8;
|
||||
fn compute_depth(shape_id: ShapeId, shapes: &[Option<Arc<Shape>>]) -> u32 {
|
||||
let mut count = 0u32;
|
||||
let mut cursor = Some(shape_id);
|
||||
while let Some(id) = cursor {
|
||||
match shapes.get((id - 1) as usize).and_then(|s| s.clone()) {
|
||||
@@ -94,10 +94,10 @@ impl ShapeForge {
|
||||
shapes.get((id - 1) as usize).and_then(|s| s.clone())
|
||||
}
|
||||
|
||||
pub fn lookup_position(&self, shape_id: ShapeId, prop_name: StringIndex) -> Option<u8> {
|
||||
pub fn lookup_position(&self, shape_id: ShapeId, prop_name: StringIndex) -> Option<u32> {
|
||||
let shapes = self.shapes.read().unwrap();
|
||||
let total_depth = Self::compute_depth(shape_id, &shapes);
|
||||
let mut step: u8 = 0;
|
||||
let mut step: u32 = 0;
|
||||
let mut cursor = Some(shape_id);
|
||||
while let Some(id) = cursor {
|
||||
match shapes.get((id - 1) as usize).and_then(|s| s.clone()) {
|
||||
@@ -131,9 +131,9 @@ impl ShapeForge {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn shape_prop_count(&self, shape_id: ShapeId) -> u8 {
|
||||
pub fn shape_prop_count(&self, shape_id: ShapeId) -> u32 {
|
||||
let shapes = self.shapes.read().unwrap();
|
||||
let mut count = 0u8;
|
||||
let mut count = 0u32;
|
||||
let mut cursor = Some(shape_id);
|
||||
while let Some(id) = cursor {
|
||||
match shapes.get((id - 1) as usize).and_then(|s| s.clone()) {
|
||||
|
||||
Reference in New Issue
Block a user