From 570a6a87c7b5ba6d0695dacc85836e472a54120f Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Fri, 25 Aug 2023 13:03:07 +0200 Subject: [PATCH] added trypush to Shape --- julia/Shape.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/julia/Shape.jl b/julia/Shape.jl index e69de29..be54ad0 100644 --- a/julia/Shape.jl +++ b/julia/Shape.jl @@ -0,0 +1,20 @@ +include("SortingModifiers.jl") + +struct Shape + cubes::Set{Tuple{Int8, Int8, Int8}} + recentCubes::Set{Tuple{Int8, Int8, Int8}} + orderedLists::Array{List{Tuple{Int8, Int8, Int8}}} +end + +function trypush!(S::Shape, t::Tuple{Int8, Int8, Int8}) + if t ∈ S.cubes + return false + else + push!(S.cubes, t) + for i ∈ 1:24 + index = searchsortedfirst(S.orderedLists[i], t, by=SortingModifiers[i]) + insert!(S.orderedLists, index, t) + end + return true + end +end