~hrbrmstr/iptools2

c23df3647ef7c6d1076d3d627d943f3ee6605fbc — hrbrmstr 2 months ago 13e8b30 master
forgot how daft g++ is
6 files changed, 65 insertions(+), 15 deletions(-)

M NAMESPACE
M R/RcppExports.R
M README.Rmd
M README.md
A man/range_boundaries.Rd
M src/iptools2-main.cpp
M NAMESPACE => NAMESPACE +1 -0
@@ 1,5 1,6 @@
# Generated by roxygen2: do not edit by hand

export(range_boundaries)
import(AsioHeaders)
importFrom(Rcpp,sourceCpp)
useDynLib(iptools2, .registration = TRUE)

M R/RcppExports.R => R/RcppExports.R +11 -0
@@ 1,6 1,17 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Retrieve range boundaries for a character vector of IPv4/IPv6 CIDRs
#'
#' @param cidr a character vector of IPv4/IPv6 CIDRs
#' @return data frame with original input, canonical CIDR, start/end (chr) of range and number of hosts.
#' @note the `n_hosts` column is a numeric vector since R cannot handle 128-bit integers easily and
#'       v4 & v6 are co-mingled.
#' @export
#' @examples
#' range_boundaries(
#'   c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "wat")
#' )
range_boundaries <- function(cidr) {
    .Call(`_iptools2_range_boundaries`, cidr)
}

M README.Rmd => README.Rmd +2 -2
@@ 40,8 40,8 @@ packageVersion("iptools2")
```

```{r u-1}
iptools2:::range_boundaries(
  c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "steve")
range_boundaries(
  c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "wat")
)
```


M README.md => README.md +10 -7
@@ 5,7 5,7 @@ developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.re
[![Signed
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)
![Signed commit
%](https://img.shields.io/badge/Signed_Commits-67%25-lightgrey.svg)
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg)
[![Linux build
Status](https://travis-ci.org/hrbrmstr/iptools2.svg?branch=master)](https://travis-ci.org/hrbrmstr/iptools2)  
![Minimal R


@@ 24,6 24,9 @@ A WIP Re-imagining of {iptools}

The following functions are implemented:

  - `range_boundaries`: Retrieve range boundaries for a character vector
    of IPv4/IPv6 CIDRs

## Installation

``` r


@@ 52,24 55,24 @@ packageVersion("iptools2")
```

``` r
iptools2:::range_boundaries(
  c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "steve")
range_boundaries(
  c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "wat")
)
##              cidr      canonical       start           end      n_hosts
## 1  2001:4801::/32 2001:4801::/32 2001:4801::   2001:4802:: 7.922816e+28
## 2 2001:0db8::/127 2001:db8::/127  2001:db8::   2001:db8::2 2.000000e+00
## 3    10.1.10.0/24   10.1.10.0/24   10.1.10.1   10.1.10.255 2.540000e+02
## 4 2001:0db8::/119 2001:db8::/119  2001:db8:: 2001:db8::200 5.120000e+02
## 5           steve           <NA>        <NA>          <NA>           NA
## 5             wat           <NA>        <NA>          <NA>           NA
```

## iptools2 Metrics

| Lang | \# Files |  (%) | LoC |  (%) | Blank lines |  (%) | \# Lines |  (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| C++  |        2 | 0.29 | 242 | 0.92 |          33 | 0.62 |        7 | 0.12 |
| Rmd  |        1 | 0.14 |  11 | 0.04 |          16 | 0.30 |       30 | 0.54 |
| R    |        4 | 0.57 |   9 | 0.03 |           4 | 0.08 |       19 | 0.34 |
| C++  |        2 | 0.29 | 241 | 0.92 |          33 | 0.62 |       18 | 0.23 |
| Rmd  |        1 | 0.14 |  11 | 0.04 |          16 | 0.30 |       30 | 0.38 |
| R    |        4 | 0.57 |   9 | 0.03 |           4 | 0.08 |       30 | 0.38 |

## Code of Conduct


A man/range_boundaries.Rd => man/range_boundaries.Rd +26 -0
@@ 0,0 1,26 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{range_boundaries}
\alias{range_boundaries}
\title{Retrieve range boundaries for a character vector of IPv4/IPv6 CIDRs}
\usage{
range_boundaries(cidr)
}
\arguments{
\item{cidr}{a character vector of IPv4/IPv6 CIDRs}
}
\value{
data frame with original input, canonical CIDR, start/end (chr) of range and number of hosts.
}
\description{
Retrieve range boundaries for a character vector of IPv4/IPv6 CIDRs
}
\note{
the \code{n_hosts} column is a numeric vector since R cannot handle 128-bit integers easily and
v4 & v6 are co-mingled.
}
\examples{
range_boundaries(
  c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "wat")
)
}

M src/iptools2-main.cpp => src/iptools2-main.cpp +15 -6
@@ 147,23 147,21 @@ static double power_lookup_tbl(unsigned pow) {
  return -1.0;
}

struct split {
  enum empties_t { empties_ok, no_empties };
};
enum empties_t { empties_ok, no_empties };

template <typename Container>
Container& split(
    Container&                            result,
    const typename Container::value_type& s,
    const typename Container::value_type& delimiters,
    split::empties_t                      empties = split::empties_ok )
    empties_t                      empties = empties_ok )
{
  result.clear();
  size_t current;
  size_t next = -1;
  do
  {
    if (empties == split::no_empties)
    if (empties == no_empties)
    {
      next = s.find_first_not_of( delimiters, next + 1 );
      if (next == Container::value_type::npos) break;


@@ 177,6 175,17 @@ Container& split(
  return result;
}

//' Retrieve range boundaries for a character vector of IPv4/IPv6 CIDRs
//'
//' @param cidr a character vector of IPv4/IPv6 CIDRs
//' @return data frame with original input, canonical CIDR, start/end (chr) of range and number of hosts.
//' @note the `n_hosts` column is a numeric vector since R cannot handle 128-bit integers easily and
//'       v4 & v6 are co-mingled.
//' @export
//' @examples
//' range_boundaries(
//'   c("2001:4801::/32", "2001:0db8::/127", "10.1.10.0/24", "2001:0db8::/119", "wat")
//' )
// [[Rcpp::export]]
DataFrame range_boundaries(std::vector < std::string > cidr) {



@@ 191,7 200,7 @@ DataFrame range_boundaries(std::vector < std::string > cidr) {
      try {
        ip::network_v6 net = ip::make_network_v6(cidr[i]);
        ip::address_v6_range rng = net.hosts();
        sz[i] = power_lookup_tbl(128-net.prefix_length());
        sz[i] = power_lookup_tbl(128 - net.prefix_length());
        canon[i] = net.canonical().to_string();
        cstart[i] = (rng.begin())->to_string();
        cend[i] = (rng.end())->to_string();