mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
Psuedo working extsort
This commit is contained in:
parent
e6c195a675
commit
c49f93c9af
2 changed files with 16 additions and 13 deletions
|
@ -17,7 +17,7 @@ path = "src/sort.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
extsort = "0.4.2"
|
extsort = "0.4.2"
|
||||||
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
|
serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
rayon = "1.5"
|
rayon = "1.5"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
|
|
@ -40,7 +40,6 @@ use std::ffi::OsString;
|
||||||
use std::usize;
|
use std::usize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::string::*;
|
use std::string::*;
|
||||||
use serde_json::Result;
|
|
||||||
|
|
||||||
static NAME: &str = "sort";
|
static NAME: &str = "sort";
|
||||||
static ABOUT: &str = "Display sorted concatenation of all FILE(s).";
|
static ABOUT: &str = "Display sorted concatenation of all FILE(s).";
|
||||||
|
@ -195,7 +194,7 @@ impl Selection {
|
||||||
|
|
||||||
type Field = Range<usize>;
|
type Field = Range<usize>;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct Line {
|
struct Line {
|
||||||
line: String,
|
line: String,
|
||||||
// The common case is not to specify fields. Let's make this fast.
|
// The common case is not to specify fields. Let's make this fast.
|
||||||
|
@ -203,18 +202,22 @@ struct Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sortable for Line {
|
impl Sortable for Line {
|
||||||
|
|
||||||
fn encode<W: Write>(&self, write: &mut W) {
|
fn encode<W: Write>(&self, write: &mut W) {
|
||||||
let line = Line { line: self.line.clone(), selections: self.selections.clone() } ;
|
let line = Line {line: self.line.clone(), selections: self.selections.clone()};
|
||||||
let serialized = serde_json::to_string(&line).unwrap();
|
let serialized = serde_json::ser::to_string(&line).unwrap();
|
||||||
write.write_all(serialized.as_bytes()).unwrap();
|
write.write_all(format!("{}{}", serialized, "\n").as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode<R: Read>(read: &mut R) -> Option<Line> {
|
fn decode<R: Read>(read: &mut R) -> Option<Line> {
|
||||||
let mut buf = String::new();
|
let buf_reader = BufReader::new(read);
|
||||||
read.read_to_string(&mut buf).ok();
|
|
||||||
let line: Option<Line> = buf;
|
let mut result: Option<Line> = None;
|
||||||
println!("deserialized = {:?}", line);
|
for line in buf_reader.lines() {
|
||||||
line
|
let line_as_str: Line = serde_json::de::from_str(&line.unwrap()).unwrap();
|
||||||
|
result = Some( Line {line: line_as_str.line, selections: line_as_str.selections} );
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +238,7 @@ impl Line {
|
||||||
.selectors
|
.selectors
|
||||||
.iter()
|
.iter()
|
||||||
.map(|selector| {
|
.map(|selector| {
|
||||||
if let Some(range) = selector.get_selection(&line, fields.as_deref()) {
|
if let Some(range) = selector.get_field_selection(&line, fields.as_deref()) {
|
||||||
if let Some(transformed) =
|
if let Some(transformed) =
|
||||||
transform(&line[range.to_owned()], &selector.settings)
|
transform(&line[range.to_owned()], &selector.settings)
|
||||||
{
|
{
|
||||||
|
@ -411,7 +414,7 @@ impl FieldSelector {
|
||||||
|
|
||||||
/// Look up the slice that corresponds to this selector for the given line.
|
/// Look up the slice that corresponds to this selector for the given line.
|
||||||
/// If needs_fields returned false, fields may be None.
|
/// If needs_fields returned false, fields may be None.
|
||||||
fn get_selection<'a>(
|
fn get_field_selection<'a>(
|
||||||
&self,
|
&self,
|
||||||
line: &'a str,
|
line: &'a str,
|
||||||
tokens: Option<&[Field]>,
|
tokens: Option<&[Field]>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue