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