Skip to content

Commit

Permalink
use back const fn for fzyzcjy/flutter_rust_bridge#2522
Browse files Browse the repository at this point in the history
  • Loading branch information
asukaminato0721 committed Jan 30, 2025
1 parent d91ee75 commit 247a306
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/migrate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'src/rust/api/fsrs_api.dart';

void migrateWithFullHistory() {
// Create a new FSRS instance with default parameters
final fsrs = new Fsrs(parameters: defaultParameters);
final fsrs = new Fsrs(parameters: defaultParameters());

// Simulate a full review history for a card
final reviews = [
Expand All @@ -20,7 +20,7 @@ void migrateWithFullHistory() {
}

void migrateWithPartialHistory() {
final fsrs = new Fsrs(parameters: defaultParameters);
final fsrs = new Fsrs(parameters: defaultParameters());

// Set the true retention of the original algorithm
const sm2Retention = 0.9;
Expand Down Expand Up @@ -48,7 +48,7 @@ void migrateWithPartialHistory() {
}

void migrateWithLatestState() {
final fsrs = new Fsrs(parameters: defaultParameters);
final fsrs = new Fsrs(parameters: defaultParameters());

// Set the true retention of the original algorithm
const sm2Retention = 0.9;
Expand Down
4 changes: 2 additions & 2 deletions lib/optimize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Future<void> main() async {
print('Number of FSRS items: ${fsrsItems.length}');

// Create FSRS instance with default parameters
final fsrs = new Fsrs(parameters: defaultParameters);
print('Default parameters: ${defaultParameters}');
final fsrs = new Fsrs(parameters: defaultParameters());
print('Default parameters: ${defaultParameters()}');

// Optimize parameters
final optimizedParameters = fsrs.computeParameters(trainSet: fsrsItems);
Expand Down
13 changes: 9 additions & 4 deletions rust/src/api/fsrs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ impl FSRSReview {
Self(fsrs::FSRSReview { rating, delta_t })
}
}
pub const DEFAULT_PARAMETERS: [f32; 19] = [
0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 0.0046, 1.54575, 0.1192, 1.01925,
1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655, 0.6621,
];

#[frb(sync)]
#[allow(non_snake_case)]
pub const fn DEFAULT_PARAMETERS() -> [f32; 19] {
[
0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 0.0046, 1.54575, 0.1192,
1.01925, 1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655, 0.6621,
]
}

0 comments on commit 247a306

Please sign in to comment.