Skip to content

Commit 963dd1d

Browse files
authored
Merge pull request #126 from traP-jp/feat/#125-depId-to-name
✨ depId->name
2 parents 0481e5f + 17cd57d commit 963dd1d

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

lib/judge_core/src/problem_registry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{identifiers::ResourceId, procedure::*};
1+
use crate::{
2+
identifiers::{DepId, ResourceId},
3+
procedure::*,
4+
};
25
use futures::Future;
36

47
/// ProblemRegistryServer uploads contents of problems to the registry in webservice-backend server.
@@ -8,6 +11,9 @@ pub trait ProblemRegistryServer {
811
&self,
912
problem: writer_schema::Procedure,
1013
) -> impl Future<Output = Result<registered::Procedure, RegistrationError>>;
14+
15+
// Convert DepId to names in writer schema
16+
fn restore_name(&self, dep_id: DepId) -> impl Future<Output = Option<String>>;
1117
}
1218

1319
/// ProblemRegistryClient fetches contents of problems from the registry in judge server.

lib/judge_core/src/writer_schema_transpiler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn transpile(
1313
(
1414
registered::Procedure,
1515
HashMap<identifiers::ResourceId, String>,
16+
HashMap<identifiers::DepId, String>,
1617
),
1718
RegistrationError,
1819
> {
@@ -137,5 +138,9 @@ pub fn transpile(
137138
.iter()
138139
.map(|(k, v)| (v.clone(), k.clone()))
139140
.collect(),
141+
name_to_id
142+
.iter()
143+
.map(|(k, v)| (v.clone(), k.clone()))
144+
.collect(),
140145
))
141146
}

lib/local_problem_registry/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pub fn new_registry() -> (
88
let registry = std::sync::Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new()));
99
let server = registry_server::RegistryServer {
1010
registry: registry.clone(),
11+
dep_id_to_name: std::sync::Arc::new(tokio::sync::Mutex::new(
12+
std::collections::HashMap::new(),
13+
)),
1114
};
1215
let client = registry_client::RegistryClient { registry };
1316
(server, client)

lib/local_problem_registry/src/registry_server.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@ use tokio::sync::Mutex;
55

66
pub struct RegistryServer {
77
pub(crate) registry: Arc<Mutex<HashMap<identifiers::ResourceId, String>>>,
8+
pub(crate) dep_id_to_name: Arc<Mutex<HashMap<identifiers::DepId, String>>>,
89
}
910

1011
impl ProblemRegistryServer for RegistryServer {
1112
async fn register(
1213
&self,
1314
procedure: writer_schema::Procedure,
1415
) -> Result<registered::Procedure, RegistrationError> {
15-
let (transpiled_procedure, content_to_register) = transpile(procedure)?;
16-
let mut registry = self.registry.lock().await;
17-
for (resource_id, content) in content_to_register {
18-
registry.insert(resource_id, content);
16+
let (transpiled_procedure, content_to_register, dep_id_to_name) = transpile(procedure)?;
17+
{
18+
let mut registry = self.registry.lock().await;
19+
for (resource_id, content) in content_to_register {
20+
registry.insert(resource_id, content);
21+
}
22+
}
23+
{
24+
let mut dep_id_to_name_global = self.dep_id_to_name.lock().await;
25+
for (dep_id, name) in dep_id_to_name {
26+
dep_id_to_name_global.insert(dep_id, name);
27+
}
1928
}
2029
Ok(transpiled_procedure)
2130
}
31+
32+
async fn restore_name(&self, dep_id: identifiers::DepId) -> Option<String> {
33+
let dep_id_to_name = self.dep_id_to_name.lock().await;
34+
dep_id_to_name.get(&dep_id).cloned()
35+
}
2236
}

0 commit comments

Comments
 (0)