2019-04-23 08:17:34 +10:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
2019-04-26 11:16:02 +10:00
|
|
|
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
2019-04-23 08:17:34 +10:00
|
|
|
*/
|
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
#include "emory/chunk/map.hpp"
|
|
|
|
#include "emory/chunk/params.hpp"
|
|
|
|
|
2019-04-23 08:17:34 +10:00
|
|
|
#include <cruft/util/io.hpp>
|
2019-04-26 11:16:02 +10:00
|
|
|
#include <cruft/util/view.hpp>
|
2019-04-23 08:55:16 +10:00
|
|
|
#include <cruft/util/parse/value.hpp>
|
2019-04-23 08:17:34 +10:00
|
|
|
|
2020-12-06 07:22:18 +11:00
|
|
|
#include <algorithm>
|
2019-04-23 08:17:34 +10:00
|
|
|
#include <iostream>
|
2020-12-06 07:22:18 +11:00
|
|
|
#include <compare>
|
2019-04-23 08:17:34 +10:00
|
|
|
|
2019-04-23 08:55:16 +10:00
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-04-23 08:55:16 +10:00
|
|
|
enum {
|
|
|
|
ARG_SELF,
|
|
|
|
ARG_BITS,
|
|
|
|
ARG_WINDOW,
|
2019-04-23 09:35:45 +10:00
|
|
|
ARGS_MINIMUM,
|
2019-04-23 08:55:16 +10:00
|
|
|
ARGS_INPUT,
|
|
|
|
|
|
|
|
NUM_ARGS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-12-06 07:22:18 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static
|
|
|
|
std::strong_ordering
|
|
|
|
region_ordering (
|
|
|
|
emory::chunk::region const &a,
|
|
|
|
emory::chunk::region const &b
|
|
|
|
) {
|
|
|
|
if (auto const cmp = a.size () <=> b.size (); cmp != 0)
|
|
|
|
return cmp;
|
|
|
|
for (int i = 0; i < std::ssize (a.digest); ++i)
|
|
|
|
if (auto const cmp = a.digest[i] <=> b.digest[i]; cmp != 0)
|
|
|
|
return cmp;
|
|
|
|
return std::strong_ordering::equal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool region_less (emory::chunk::region const &a, emory::chunk::region const &b)
|
|
|
|
{
|
|
|
|
return region_ordering (a, b) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool region_equal (emory::chunk::region const &a, emory::chunk::region const &b)
|
|
|
|
{
|
|
|
|
return region_ordering (a, b) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//static bool overlap (emory::chunk::region const &a, emory::chunk::region const &b)
|
|
|
|
//{
|
|
|
|
// return a.offset.first < b.offset.second &&
|
|
|
|
// b.offset.first < a.offset.second;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2019-04-23 08:17:34 +10:00
|
|
|
int main (int argc, char const **argv)
|
|
|
|
{
|
2019-04-23 08:55:16 +10:00
|
|
|
if (argc != NUM_ARGS) {
|
2019-04-23 09:35:45 +10:00
|
|
|
std::cerr << "usage: " << argv[ARG_SELF] << " <bits> <window> <minimum> <input>\n";
|
2019-04-23 08:55:16 +10:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
emory::chunk::params const p {
|
|
|
|
.bits = cruft::parse::from_string<std::size_t> (argv[ARG_BITS ]),
|
|
|
|
.window = cruft::parse::from_string<std::size_t> (argv[ARG_WINDOW]),
|
|
|
|
.minimum = cruft::parse::from_string<std::ptrdiff_t> (argv[ARGS_MINIMUM]),
|
|
|
|
};
|
2019-04-23 08:17:34 +10:00
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
cruft::mapped_file data (argv[ARGS_INPUT]);
|
|
|
|
emory::chunk::map src (data, p);
|
2019-04-23 08:17:34 +10:00
|
|
|
|
2019-04-26 11:16:02 +10:00
|
|
|
std::cout << src.size () << " chunks\n";
|
2019-04-23 08:17:34 +10:00
|
|
|
}
|