Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions const-oid/oiddbgen/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp::Ordering;

use convert_case::{Case, Casing};
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
Expand All @@ -9,6 +11,24 @@ pub struct Node {
symb: Ident,
}

impl Ord for Node {
fn cmp(&self, other: &Self) -> Ordering {
match self.obid.cmp(&other.obid) {
Ordering::Equal => match self.name.len().cmp(&other.name.len()) {
Ordering::Equal => self.name.cmp(&other.name),
o => o,
},
o => o,
}
}
}

impl PartialOrd for Node {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Node {
pub fn new(obid: String, name: String) -> Self {
// Raise the first letter in the beginning or after a hyphen.
Expand Down
2 changes: 1 addition & 1 deletion const-oid/oiddbgen/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Root {
self.0
.entry(spec)
.or_insert_with(Spec::default)
.push(Node::new(obid, name));
.insert(Node::new(obid, name));
}

pub fn module(&self) -> TokenStream {
Expand Down
8 changes: 5 additions & 3 deletions const-oid/oiddbgen/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::collections::BTreeSet;

use proc_macro2::{Ident, TokenStream};
use quote::quote;

use crate::node::Node;

#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct Spec(Vec<Node>);
pub struct Spec(BTreeSet<Node>);

impl Spec {
pub fn push(&mut self, value: Node) {
self.0.push(value)
pub fn insert(&mut self, value: Node) -> bool {
self.0.insert(value)
}

pub fn records(&self, path: TokenStream) -> TokenStream {
Expand Down
Loading