diff options
Diffstat (limited to 'graph-checker/src/main.rs')
| -rw-r--r-- | graph-checker/src/main.rs | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/graph-checker/src/main.rs b/graph-checker/src/main.rs index 2f3de7a..f38724c 100644 --- a/graph-checker/src/main.rs +++ b/graph-checker/src/main.rs @@ -1,4 +1,4 @@ -use sqlx::migrate::MigrateDatabase; +use sqlx::{migrate::MigrateDatabase, QueryBuilder, Sqlite}; use std::time::Instant; use tokio; @@ -18,38 +18,49 @@ async fn main() -> Result<(), sqlx::Error> { sqlx::Sqlite::create_database(&database_url).await?; } let db = sqlx::SqlitePool::connect(&database_url).await?; - let _ = sqlx::query!( + let err = sqlx::query( "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL, ind_dom INT NOT NULL, forced_geod INT NOT NULL);" ) .execute(&db) .await; + if let Err(e) = err { + println!("Error while creating table: {e}"); + } let gi = GengIterator::new(9); - let start = Instant::now(); - println!("Started"); - const BATCH_SIZE: usize = 10000; + let start = Instant::now(); + const BATCH_SIZE: usize = 1000; let mut count = 0; loop { let graphs = gi.take(BATCH_SIZE); let batch = Instant::now(); let tasks: Vec<_> = graphs - .map(|g| { - let db = db.clone(); - tokio::spawn(async move { - let (g6, ind_dom, fg) = compute::dominating_numbers(g).await; - let ind_dom = ind_dom.unwrap_or(0); - let fg = fg.unwrap_or(0); - let _ = sqlx::query!( - "INSERT INTO graphs (g6, ind_dom, forced_geod) VALUES (?, ?, ?);", - g6, ind_dom, fg - ).execute(&db).await; - }) - }) + .map(|g| tokio::spawn(compute::dominating_numbers(g))) .collect(); let part = futures::future::join_all(tasks).await; let sz = part.len(); + + let mut query = QueryBuilder::<Sqlite>::new( + "INSERT INTO graphs (g6, ind_dom, forced_geod) ", + ); + query.push_values(part, |mut b, res| { + match res { + Ok((g6, ind_dom, fg)) => { + b.push_bind(g6) + .push_bind(ind_dom.unwrap_or(0)) + .push_bind(fg.unwrap_or(0)); + } + Err(_) => println!("Unable to push into query"), + }; + }); + + let err = query.build().execute(&db).await; + if let Err(e) = err { + println!("Error while inserting: {e}"); + } + count += sz; println!( "Counted {count} in {}s", |