Skip to content
This repository has been archived by the owner on Apr 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from p-ranav/improvements
Browse files Browse the repository at this point in the history
Improvements based on Reddit feedback
  • Loading branch information
p-ranav committed Apr 23, 2019
2 parents c37ada0 + 1e5c00c commit 1217c0d
Show file tree
Hide file tree
Showing 13 changed files with 1,783 additions and 2,437 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Header-only library
* Fast, asynchronous, multi-threaded processing using:
- [Lock-free Concurrent Queues](https://github.com/cameron314/concurrentqueue)
- [Robin hood Hashing](https://github.com/Tessil/robin-map)
* Requires C++11
- [Robin hood Hashing](https://github.com/martinus/robin-hood-hashing)
* Requires C++17
* MIT License

## Table of Contents
Expand All @@ -29,7 +29,7 @@
Simply include reader.hpp and you're good to go.

```cpp
#include <reader.hpp>
#include <csv/reader.hpp>
```
To start parsing CSV files, create a ```csv::Reader``` object and call ```.read(filename)```.

Expand All @@ -43,8 +43,8 @@ This ```.read``` method is non-blocking. The reader spawns multiple threads to t
```cpp
while(foo.busy()) {
if (foo.has_row()) {
auto row = foo.next_row(); // Each row is a robin_map (https://github.com/Tessil/robin-map)
auto foo = row["foo"] // You can use it just like an std::unordered_map
auto row = foo.next_row(); // Each row is a csv::unordered_flat_map (github.com/martinus/robin-hood-hashing)
auto foo = row["foo"] // You can use it just like an std::unordered_map
auto bar = row["bar"];
// do something
}
Expand Down Expand Up @@ -256,7 +256,7 @@ Note: Do not provide num_rows greater than the actual number of rows in the file
void parse(const std::string& filename) {
csv::Reader foo;
foo.read(filename);
std::vector<csv::robin_map<std::string, std::string>> rows;
std::vector<csv::unordered_flat_map<std::string_view, std::string>> rows;
while (foo.busy()) {
if (foo.ready()) {
auto row = foo.next_row();
Expand All @@ -267,7 +267,7 @@ void parse(const std::string& filename) {
```
```bash
$ g++ -pthread -std=c++11 -O3 -Iinclude/ -o test benchmark.cpp
$ g++ -pthread -std=c++17 -O3 -Iinclude/ -o test benchmark.cpp
$ time ./test
```

Expand All @@ -289,7 +289,7 @@ Here are the average-case execution times:
Simply include writer.hpp and you're good to go.

```cpp
#include <writer.hpp>
#include <csv/writer.hpp>
```
To start writing CSV files, create a ```csv::Writer``` object and provide a filename:

Expand All @@ -308,13 +308,13 @@ foo.configure_dialect()
Now it's time to write rows. You can do this in multiple ways:

```cpp
foo.write_row("1", "2", "3"); // parameter packing
foo.write_row({"4", "5", "6"}); // std::vector
foo.write_row(std::map<std::string, std::string>{ // std::map
foo.write_row("1", "2", "3"); // parameter packing
foo.write_row({"4", "5", "6"}); // std::vector
foo.write_row(std::map<std::string, std::string>{ // std::map
{"a", "7"}, {"b", "8"}, {"c", "9"} });
foo.write_row(std::unordered_map<std::string, std::string>{ // std::unordered_map
foo.write_row(std::unordered_map<std::string, std::string>{ // std::unordered_map
{"a", "7"}, {"b", "8"}, {"c", "9"} });
foo.write_row(csv::robin_map<std::string, std::string>{ // robin_map
foo.write_row(csv::unordered_flat_map<std::string, std::string>{ // csv::unordered_flat_map
{"a", "7"}, {"b", "8"}, {"c", "9"} });
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Tessil
Copyright (c) 2018-2019 Martin Ankerl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions include/dialect.hpp → include/csv/dialect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <csv/robin_hood.hpp>
#include <string>
#include <vector>
#include <robin_map.hpp>
#include <string_view>

namespace csv {

Expand All @@ -43,7 +44,7 @@ namespace csv {
char line_terminator_;
char quote_character_;
bool double_quote_;
robin_map<std::string, bool> ignore_columns_;
unordered_flat_map<std::string_view, bool> ignore_columns_;
std::vector<char> trim_characters_;
std::vector<std::string> column_names_;
bool header_;
Expand Down
Loading

0 comments on commit 1217c0d

Please sign in to comment.