|
@ -1,7 +1,7 @@ |
|
|
#[cxx::bridge(namespace = "klotski::ffi")] |
|
|
#[cxx::bridge(namespace = "klotski::ffi")] |
|
|
mod ffi { |
|
|
mod ffi { |
|
|
#[derive(Debug)] |
|
|
#[derive(Debug)] |
|
|
struct RsCommonCode { |
|
|
struct RsLayout { |
|
|
code: u64, |
|
|
code: u64, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -11,37 +11,37 @@ mod ffi { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsafe extern "C++" { |
|
|
unsafe extern "C++" { |
|
|
include!("rust_ffi/include/common_code.h"); |
|
|
include!("rust_ffi/include/layout.h"); |
|
|
|
|
|
|
|
|
/// only for internal use
|
|
|
/// only for internal use
|
|
|
fn common_code_check(val: u64) -> bool; |
|
|
fn layout_check(val: u64) -> bool; |
|
|
|
|
|
|
|
|
/// only for internal use
|
|
|
/// only for internal use
|
|
|
fn common_code_from_str(s: &str) -> u64; |
|
|
fn layout_from_str(s: &str) -> u64; |
|
|
|
|
|
|
|
|
/// Convert CommonCode to string form.
|
|
|
/// Convert Layout to string form.
|
|
|
fn to_string(self: &RsCommonCode) -> String; |
|
|
fn to_string(self: &RsLayout) -> String; |
|
|
|
|
|
|
|
|
/// Convert CommonCode to shorten string form.
|
|
|
/// Convert Layout to shorten string form.
|
|
|
fn to_shorten_string(self: &RsCommonCode) -> String; |
|
|
fn to_shorten_string(self: &RsLayout) -> String; |
|
|
|
|
|
|
|
|
/// Convert CommonCode to ShortCode.
|
|
|
/// Convert Layout to ShortCode.
|
|
|
fn to_short_code(self: &RsCommonCode) -> RsShortCode; |
|
|
fn to_short_code(self: &RsLayout) -> RsShortCode; |
|
|
|
|
|
|
|
|
/// Whether the layout is vertically symmetrical.
|
|
|
/// Whether the layout is vertically symmetrical.
|
|
|
fn is_vertical_mirror(self: &RsCommonCode) -> bool; |
|
|
fn is_vertical_mirror(self: &RsLayout) -> bool; |
|
|
|
|
|
|
|
|
/// Whether the layout is horizontally symmetrical.
|
|
|
/// Whether the layout is horizontally symmetrical.
|
|
|
fn is_horizontal_mirror(self: &RsCommonCode) -> bool; |
|
|
fn is_horizontal_mirror(self: &RsLayout) -> bool; |
|
|
|
|
|
|
|
|
/// Calculate the vertically symmetrical klotski layout.
|
|
|
/// Calculate the vertically symmetrical klotski layout.
|
|
|
fn to_vertical_mirror(self: &RsCommonCode) -> RsCommonCode; |
|
|
fn to_vertical_mirror(self: &RsLayout) -> RsLayout; |
|
|
|
|
|
|
|
|
/// Calculate the horizontally symmetrical klotski layout.
|
|
|
/// Calculate the horizontally symmetrical klotski layout.
|
|
|
fn to_horizontal_mirror(self: &RsCommonCode) -> RsCommonCode; |
|
|
fn to_horizontal_mirror(self: &RsLayout) -> RsLayout; |
|
|
|
|
|
|
|
|
/// Obtain all next cases in CommonCode.
|
|
|
/// Obtain all next cases in Layout.
|
|
|
fn next_cases(self: &RsCommonCode) -> Vec<RsCommonCode>; |
|
|
fn next_cases(self: &RsLayout) -> Vec<RsLayout>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsafe extern "C++" { |
|
|
unsafe extern "C++" { |
|
@ -56,29 +56,29 @@ mod ffi { |
|
|
/// Convert ShortCode to string form.
|
|
|
/// Convert ShortCode to string form.
|
|
|
fn to_string(self: &RsShortCode) -> String; |
|
|
fn to_string(self: &RsShortCode) -> String; |
|
|
|
|
|
|
|
|
/// Convert ShortCode to CommonCode.
|
|
|
/// Convert ShortCode to Layout.
|
|
|
fn to_common_code(self: &RsShortCode) -> RsCommonCode; |
|
|
fn to_layout(self: &RsShortCode) -> RsLayout; |
|
|
|
|
|
|
|
|
/// Build the conversion index for ShortCode.
|
|
|
/// Build the conversion index for ShortCode.
|
|
|
fn short_code_speed_up(fast_mode: bool); |
|
|
fn short_code_speed_up(fast_mode: bool); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub use ffi::RsLayout as Layout; |
|
|
pub use ffi::RsShortCode as ShortCode; |
|
|
pub use ffi::RsShortCode as ShortCode; |
|
|
pub use ffi::RsCommonCode as CommonCode; |
|
|
|
|
|
|
|
|
|
|
|
impl CommonCode { |
|
|
impl Layout { |
|
|
/// Check the validity of the original CommonCode.
|
|
|
/// Check the validity of the original Layout.
|
|
|
pub fn check(code: u64) -> bool { |
|
|
pub fn check(code: u64) -> bool { |
|
|
ffi::common_code_check(code) |
|
|
ffi::layout_check(code) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Create CommonCode without any check.
|
|
|
/// Create Layout without any check.
|
|
|
pub fn unsafe_create(code: u64) -> Self { |
|
|
pub fn unsafe_create(code: u64) -> Self { |
|
|
Self { code } |
|
|
Self { code } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Create CommonCode with validity check.
|
|
|
/// Create Layout with validity check.
|
|
|
pub fn create(code: u64) -> Option<Self> { |
|
|
pub fn create(code: u64) -> Option<Self> { |
|
|
if Self::check(code) { |
|
|
if Self::check(code) { |
|
|
return Some(Self::unsafe_create(code)); |
|
|
return Some(Self::unsafe_create(code)); |
|
@ -91,9 +91,9 @@ impl CommonCode { |
|
|
self.code |
|
|
self.code |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Create CommonCode from string form.
|
|
|
/// Create Layout from string form.
|
|
|
pub fn from_string(s: &str) -> Option<Self> { |
|
|
pub fn from_string(s: &str) -> Option<Self> { |
|
|
let val = ffi::common_code_from_str(s); |
|
|
let val = ffi::layout_from_str(s); |
|
|
if val < 0x10_FFFF_FFFF { |
|
|
if val < 0x10_FFFF_FFFF { |
|
|
return Some(Self::unsafe_create(val)); |
|
|
return Some(Self::unsafe_create(val)); |
|
|
} |
|
|
} |
|
@ -139,7 +139,7 @@ impl ShortCode { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl PartialEq for CommonCode { |
|
|
impl PartialEq for Layout { |
|
|
fn eq(&self, other: &Self) -> bool { |
|
|
fn eq(&self, other: &Self) -> bool { |
|
|
self.code == other.code |
|
|
self.code == other.code |
|
|
} |
|
|
} |
|
|