nushell/crates/nu-command/src/formats/to/mod.rs
raccmonteiro 75cb3fcc5f
uniq and uniq-by optimization (#7477) (#7534)
# Description

Refactored the quadratic complexity on `uniq` to use a HashMap, as key I
converted the Value to string.
I tried to use the HashableValue, but it looks it is not very developed
yet and it was getting more complex and difficult.

This improves performance on large data sets.

Fixes https://github.com/nushell/nushell/issues/7477


# Tests + Formatting
```
> let data = fetch "https://home.treasury.gov/system/files/276/yield-curve-rates-1990-2021.csv"
> $data | uniq
```

it keeps original attribute order in Records:
```
> [ {b:2, a:1} {a:1, b:2} ] | uniq 
╭───┬───┬───╮
│ # │ b │ a │
├───┼───┼───┤
│ 0 │ 2 │ 1 │
╰───┴───┴───╯
```
2023-01-04 11:35:49 -08:00

30 lines
476 B
Rust

mod command;
mod csv;
mod delimited;
mod html;
mod json;
mod md;
mod nuon;
mod text;
mod toml;
mod tsv;
mod url;
mod xml;
mod yaml;
pub use self::csv::ToCsv;
pub use self::toml::ToToml;
pub use self::url::ToUrl;
pub use command::To;
pub use html::ToHtml;
pub use json::ToJson;
pub use md::ToMd;
pub use nuon::value_to_string;
pub use nuon::ToNuon;
pub use text::ToText;
pub use tsv::ToTsv;
pub use xml::ToXml;
pub use yaml::ToYaml;
pub(crate) use json::value_to_json_value;