Skip to content

Commit

Permalink
simplify hash function to always just use the pretty_print function
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed May 18, 2024
1 parent 2e505e4 commit c55a623
Showing 1 changed file with 1 addition and 134 deletions.
135 changes: 1 addition & 134 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,141 +860,8 @@ impl Operation {
let mut hasher = Sha256::new();

hasher.update("cadmium".as_bytes()); // mm, salt
match self {
Operation::Create { nonce } => hasher.update(format!("{nonce}").as_bytes()),
Operation::Describe {
description,
commit,
} => hasher.update(format!("{description}-{commit}").as_bytes()),
Operation::Alias { original, new } => {
hasher.update(format!("{original}-{new}").as_bytes())
}
Operation::CreateProject { nonce } => hasher.update(format!("{nonce}").as_bytes()),
Operation::SetProjectName { project_id, name } => {
hasher.update(format!("{project_id}-{name}").as_bytes())
}
Operation::CreateWorkbench { nonce } => hasher.update(format!("{nonce}").as_bytes()),
Operation::SetWorkbenchName { workbench_id, name } => {
hasher.update(format!("{workbench_id}-{name}").as_bytes())
}

Operation::CreatePlane {
nonce,
workbench_id,
} => hasher.update(format!("{nonce}-{workbench_id}").as_bytes()),
Operation::SetPlaneName { plane_id, name } => {
hasher.update(format!("{plane_id}-{name}").as_bytes())
}
Operation::SetPlane { plane_id, plane } => {
hasher.update(format!("{plane_id}-{plane:?}").as_bytes())
}
Operation::CreateRealPlane {
plane_id,
real_plane,
} => hasher.update(format!("{plane_id}-{real_plane:?}").as_bytes()),
Operation::CreateSketch {
nonce,
workbench_id,
} => hasher.update(format!("{nonce}-{workbench_id}").as_bytes()),
Operation::SetSketchName { sketch_id, name } => {
hasher.update(format!("{sketch_id}-{name}").as_bytes())
}
Operation::SetSketchPlane {
sketch_id,
plane_id,
} => hasher.update(format!("{sketch_id}-{plane_id}").as_bytes()),
Operation::AddSketchRectangle {
sketch_id,
x,
y,
width,
height,
} => hasher.update(format!("{sketch_id}-{x}-{y}-{width}-{height}").as_bytes()),
Operation::AddSketchCircle {
sketch_id,
x,
y,
radius,
} => hasher.update(format!("{sketch_id}-{x}-{y}-{radius}").as_bytes()),
Operation::AddSketchLine {
sketch_id,
start,
end,
} => hasher.update(format!("{sketch_id}-{start:?}-{end:?}").as_bytes()),
Operation::AddSketchHandle {
sketch_id,
position,
} => hasher.update(format!("{sketch_id}-{position:?}").as_bytes()),
Operation::FinalizeSketch {
sketch_id,
workbench_id,
} => hasher.update(format!("{sketch_id}-{workbench_id}").as_bytes()),
Operation::CreateRealSketch {
sketch_id,
real_sketch,
} => {
let points_str: String = real_sketch
.points
.iter()
.sorted_by_key(|p| p.0)
.map(|p| format!("{:?}", p))
.collect();
hasher.update(format!("{sketch_id}-{points_str:?}").as_bytes())
}

Operation::CreateFace {
workbench_id,
sketch_id,
face,
} => hasher.update(format!("{workbench_id}-{sketch_id}-{face:?}").as_bytes()),
Operation::CreateTruckFace {
workbench_id,
solid_id,
face,
} => hasher.update(format!("{}", self.pretty_print()).as_bytes()),

Operation::CreateExtrusion {
nonce,
workbench_id,
} => hasher.update(format!("{nonce}-{workbench_id}").as_bytes()),
Operation::SetExtrusionName { extrusion_id, name } => {
hasher.update(format!("{extrusion_id}-{name}").as_bytes())
}
Operation::SetExtrusionSketch {
extrusion_id,
sketch_id,
} => hasher.update(format!("{extrusion_id}-{sketch_id}").as_bytes()),
Operation::SetExtrusionHandles {
extrusion_id,
handles,
} => {
hasher.update(format!("{extrusion_id}").as_bytes());
for sha in handles {
hasher.update(format!("{sha}").as_bytes())
}
}
Operation::SetExtrusionDepth {
extrusion_id,
depth,
} => hasher.update(format!("{extrusion_id}-{depth}").as_bytes()),
Operation::SetExtrusionFaces {
extrusion_id,
faces,
} => {
hasher.update(format!("{extrusion_id}").as_bytes());
for sha in faces {
hasher.update(format!("{sha}").as_bytes())
}
}
Operation::CreateSolid { nonce, solid } => {
let str = self.pretty_print();
hasher.update(format!("{nonce}-{str:?}").as_bytes())
}
Operation::FuseSolids { solid1, solid2 } => {
hasher.update(format!("{solid1}-{solid2}").as_bytes())
}
Operation::DeleteSolid { solid_id } => hasher.update(format!("{solid_id}").as_bytes()),
}
hasher.update(format!("{:?}", self.pretty_print()).as_bytes());

format!("{:x}", hasher.finalize())
}
Expand Down

0 comments on commit c55a623

Please sign in to comment.