From 68f1b90ad0d204907beb58304d0bd06391001a4d Mon Sep 17 00:00:00 2001 From: Eugene Kliuchnikov Date: Wed, 18 Aug 2021 19:15:07 +0200 Subject: Update (#918) Prepare to use copybara worklow. --- research/BUILD | 6 ++---- research/BUILD.libdivsufsort | 1 + research/Makefile | 17 ----------------- research/WORKSPACE | 24 +++++++++++++++++++++--- research/deorummolae.cc | 2 +- research/draw_histogram.cc | 39 +++++++++++++++++++-------------------- research/durchschlag.cc | 2 +- research/esaxx | 1 - research/find_opt_references.cc | 21 +++++++++++---------- research/libdivsufsort | 1 - 10 files changed, 56 insertions(+), 58 deletions(-) delete mode 100644 research/Makefile delete mode 160000 research/esaxx delete mode 160000 research/libdivsufsort (limited to 'research') diff --git a/research/BUILD b/research/BUILD index 7b7d81b..ef6967e 100644 --- a/research/BUILD +++ b/research/BUILD @@ -7,10 +7,8 @@ licenses(["notice"]) # MIT cc_library( name = "dm", srcs = ["deorummolae.cc"], - hdrs = [ - "deorummolae.h", - "esaxx/sais.hxx", - ], + deps = ["@esaxx//:sais"], + hdrs = ["deorummolae.h"], ) cc_library( diff --git a/research/BUILD.libdivsufsort b/research/BUILD.libdivsufsort index ce60e9c..a6deb5b 100644 --- a/research/BUILD.libdivsufsort +++ b/research/BUILD.libdivsufsort @@ -19,6 +19,7 @@ cc_library( "-DHAVE_CONFIG_H=1", ], includes = ["include"], + include_prefix = "third_party/libdivsufsort", ) commom_awk_replaces = ( diff --git a/research/Makefile b/research/Makefile deleted file mode 100644 index 751b316..0000000 --- a/research/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -CC = g++ -CFLAGS += -O2 -CPPFLAGS += -std=c++11 -SOURCES = $(wildcard *.cc) -EXECUTABLES = $(SOURCES:.cc=) -BINDIR = bin - -all: $(EXECUTABLES) - -$(BINDIR): - mkdir -p $@ - -$(EXECUTABLES): $(BINDIR) - $(CC) $(CFLAGS) $(CPPFLAGS) $(addsuffix .cc, $@) -o $(BINDIR)/$@ -lgflags_nothreads - -clean: - rm -rf $(BINDIR) diff --git a/research/WORKSPACE b/research/WORKSPACE index bb0f8ca..358f87d 100644 --- a/research/WORKSPACE +++ b/research/WORKSPACE @@ -1,12 +1,30 @@ workspace(name = "org_brotli_research") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + local_repository( name = "org_brotli", path = "..", ) -new_local_repository( +new_git_repository( name = "divsufsort", - build_file = "BUILD.libdivsufsort", - path = "libdivsufsort", + build_file = "@//:BUILD.libdivsufsort", + commit = "5f60d6f026c30fb4ac296f696b3c8b0eb71bd428", + remote = "https://github.com/y-256/libdivsufsort", +) + +new_git_repository( + name = "esaxx", + build_file_content = """ +package(default_visibility = ["//visibility:public"]) +cc_library( + name = "sais", + hdrs = ["sais.hxx"], + includes = ["."], + include_prefix = "third_party/esaxx", +) +""", + commit = "ca7cb332011ec37a8436487f210f396b84bd8273", + remote = "https://github.com/hillbig/esaxx", ) diff --git a/research/deorummolae.cc b/research/deorummolae.cc index d15b7ee..f12acd1 100644 --- a/research/deorummolae.cc +++ b/research/deorummolae.cc @@ -3,7 +3,7 @@ #include #include -#include "./esaxx/sais.hxx" +#include "third_party/esaxx/sais.hxx" /* Used for quick SA-entry to file mapping. Each file is padded to size that is a multiple of chunk size. */ diff --git a/research/draw_histogram.cc b/research/draw_histogram.cc index 6ea4069..5341dc1 100644 --- a/research/draw_histogram.cc +++ b/research/draw_histogram.cc @@ -18,6 +18,7 @@ #include using gflags::ParseCommandLineFlags; +#include "third_party/absl/flags/flag.h" #include "./read_dist.h" DEFINE_int32(height, 1000, "Height of the resulting histogam."); @@ -32,7 +33,7 @@ DEFINE_bool(linear, false, "True if using linear distance mapping."); DEFINE_uint64(skip, 0, "Number of bytes to skip."); inline double DistanceTransform(double x) { - static bool linear = FLAGS_linear; + static bool linear = absl::GetFlag(FLAGS_linear); if (linear) { return x; } else { @@ -48,14 +49,12 @@ inline double DensityTransform(double x) { return sqrt(255 * 255 - z * z); } -inline int GetMaxDistance() { - return FLAGS_max_distance; -} +inline int GetMaxDistance() { return absl::GetFlag(FLAGS_max_distance); } void AdjustPosition(int* pos) { static uint32_t offset = 0; static int last = 0; - static uint32_t window_size = (1 << FLAGS_brotli_window); + static uint32_t window_size = (1 << absl::GetFlag(FLAGS_brotli_window)); assert(*pos >= 0 && *pos < window_size); if (*pos < last) { offset += window_size; @@ -65,10 +64,10 @@ void AdjustPosition(int* pos) { } void BuildHistogram(FILE* fin, int** histo) { - int height = FLAGS_height; - int width = FLAGS_width; - int skip = FLAGS_skip; - size_t min_distance = FLAGS_min_distance; + int height = absl::GetFlag(FLAGS_height); + int width = absl::GetFlag(FLAGS_width); + int skip = absl::GetFlag(FLAGS_skip); + size_t min_distance = absl::GetFlag(FLAGS_min_distance); printf("height = %d, width = %d\n", height, width); @@ -78,7 +77,7 @@ void BuildHistogram(FILE* fin, int** histo) { } } - int max_pos = FLAGS_size - skip; + int max_pos = absl::GetFlag(FLAGS_size) - skip; double min_dist = min_distance > 0 ? DistanceTransform(min_distance) : 0; double max_dist = DistanceTransform(GetMaxDistance()) - min_dist; int copy, pos, distance, x, y; @@ -86,7 +85,7 @@ void BuildHistogram(FILE* fin, int** histo) { while (ReadBackwardReference(fin, ©, &pos, &distance)) { if (pos == -1) continue; // In case when only insert is present. if (distance < min_distance || distance >= GetMaxDistance()) continue; - if (FLAGS_brotli_window != -1) { + if (absl::GetFlag(FLAGS_brotli_window) != -1) { AdjustPosition(&pos); } if (pos >= skip && distance <= pos) { @@ -102,7 +101,7 @@ void BuildHistogram(FILE* fin, int** histo) { assert(y >= 0 && y < width); } - if (FLAGS_with_copies) { + if (absl::GetFlag(FLAGS_with_copies)) { int right = 1ul * (pos + copy - 1) * width / max_pos; if (right < 0) { printf("pos = %d, distance = %d, copy = %d, y = %d, right = %d\n", @@ -131,8 +130,8 @@ void BuildHistogram(FILE* fin, int** histo) { } void ConvertToPixels(int** histo, uint8_t** pixel) { - int height = FLAGS_height; - int width = FLAGS_width; + int height = absl::GetFlag(FLAGS_height); + int width = absl::GetFlag(FLAGS_width); int maxs = 0; for (int i = 0; i < height; i++) { @@ -141,7 +140,7 @@ void ConvertToPixels(int** histo, uint8_t** pixel) { } } - bool simple = FLAGS_simple; + bool simple = absl::GetFlag(FLAGS_simple); double max_histo = static_cast(maxs); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { @@ -156,8 +155,8 @@ void ConvertToPixels(int** histo, uint8_t** pixel) { } void DrawPixels(uint8_t** pixel, FILE* fout) { - int height = FLAGS_height; - int width = FLAGS_width; + int height = absl::GetFlag(FLAGS_height); + int width = absl::GetFlag(FLAGS_width); fprintf(fout, "P5\n%d %d\n255\n", width, height); for (int i = height - 1; i >= 0; i--) { @@ -166,14 +165,14 @@ void DrawPixels(uint8_t** pixel, FILE* fout) { } int main(int argc, char* argv[]) { - ParseCommandLineFlags(&argc, &argv, true); + base::ParseCommandLine(&argc, &argv); if (argc != 3) { printf("usage: draw_histogram.cc data output_file\n"); return 1; } - int height = FLAGS_height; - int width = FLAGS_width; + int height = absl::GetFlag(FLAGS_height); + int width = absl::GetFlag(FLAGS_width); FILE* fin = fopen(argv[1], "r"); FILE* fout = fopen(argv[2], "wb"); diff --git a/research/durchschlag.cc b/research/durchschlag.cc index 2fbf41b..6cbdd8c 100644 --- a/research/durchschlag.cc +++ b/research/durchschlag.cc @@ -3,7 +3,7 @@ #include #include /* terminate */ -#include "divsufsort.h" +#include "third_party/libdivsufsort/include/divsufsort.h" /* Pointer to position in text. */ typedef DurchschlagTextIdx TextIdx; diff --git a/research/esaxx b/research/esaxx deleted file mode 160000 index ca7cb33..0000000 --- a/research/esaxx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ca7cb332011ec37a8436487f210f396b84bd8273 diff --git a/research/find_opt_references.cc b/research/find_opt_references.cc index 378d3b5..96abce4 100644 --- a/research/find_opt_references.cc +++ b/research/find_opt_references.cc @@ -19,7 +19,8 @@ #include using gflags::ParseCommandLineFlags; -#include "./esaxx/sais.hxx" +#include "third_party/absl/flags/flag.h" +#include "third_party/esaxx/sais.hxx" DEFINE_bool(advanced, false, "Advanced searching mode: finds all longest " "matches at positions that are not covered by matches of length at least " @@ -91,7 +92,7 @@ inline void PrintReference(sarray_type* sarray, lcp_type* lcp, size_t size, inline void GoLeft(sarray_type* sarray, lcp_type* lcp, int idx, int left_ix, int left_lcp, entry_type* entry) { entry->first = left_lcp; - if (left_lcp > FLAGS_long_length) return; + if (left_lcp > absl::GetFlag(FLAGS_long_length)) return; for (; left_ix >= 0; --left_ix) { if (lcp[left_ix] < left_lcp) break; if (sarray[left_ix] < idx) { @@ -103,7 +104,7 @@ inline void GoLeft(sarray_type* sarray, lcp_type* lcp, int idx, int left_ix, inline void GoRight(sarray_type* sarray, lcp_type* lcp, int idx, size_t size, int right_ix, int right_lcp, entry_type* entry) { entry->first = right_lcp; - if (right_lcp > FLAGS_long_length) return; + if (right_lcp > absl::GetFlag(FLAGS_long_length)) return; for (; right_ix < size - 1; ++right_ix) { if (lcp[right_ix] < right_lcp) break; if (sarray[right_ix] < idx) { @@ -129,8 +130,8 @@ inline void StoreReference(sarray_type* sarray, lcp_type* lcp, size_t size, void ProcessReferences(sarray_type* sarray, lcp_type* lcp, size_t size, uint32_t* pos, const Fn& process_output) { - int min_length = FLAGS_min_length; - for (int idx = FLAGS_skip; idx < size; ++idx) { + int min_length = absl::GetFlag(FLAGS_min_length); + for (int idx = absl::GetFlag(FLAGS_skip); idx < size; ++idx) { int left_lcp = -1; int left_ix; for (left_ix = pos[idx] - 1; left_ix >= 0; --left_ix) { @@ -162,7 +163,7 @@ void ProcessReferences(sarray_type* sarray, lcp_type* lcp, size_t size, } void ProcessEntries(entry_type* entries, size_t size, FILE* fout) { - int long_length = FLAGS_long_length; + int long_length = absl::GetFlag(FLAGS_long_length); std::vector > segments; size_t idx; for (idx = 0; idx < size;) { @@ -195,7 +196,7 @@ void ProcessEntries(entry_type* entries, size_t size, FILE* fout) { } int main(int argc, char* argv[]) { - ParseCommandLineFlags(&argc, &argv, true); + base::ParseCommandLine(&argc, &argv); if (argc != 3) { printf("usage: %s input_file output_file\n", argv[0]); return 1; @@ -235,7 +236,7 @@ int main(int argc, char* argv[]) { using std::placeholders::_7; using std::placeholders::_8; entry_type* entries; - if (FLAGS_advanced) { + if (absl::GetFlag(FLAGS_advanced)) { entries = new entry_type[input_size]; for (size_t i = 0; i < input_size; ++i) entries[i].first = -1; } @@ -243,10 +244,10 @@ int main(int argc, char* argv[]) { Fn store = std::bind(StoreReference, _1, _2, _3, _4, _5, _6, _7, _8, entries); ProcessReferences(sarray, lcp, input_size, pos, - FLAGS_advanced ? store : print); + absl::GetFlag(FLAGS_advanced) ? store : print); printf("References processed.\n"); - if (FLAGS_advanced) { + if (absl::GetFlag(FLAGS_advanced)) { int good_cnt = 0; uint64_t avg_cnt = 0; for (size_t i = 0; i < input_size; ++i) { diff --git a/research/libdivsufsort b/research/libdivsufsort deleted file mode 160000 index 5f60d6f..0000000 --- a/research/libdivsufsort +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f60d6f026c30fb4ac296f696b3c8b0eb71bd428 -- cgit v1.1