Verified Commit a1b1b0a2 authored by Artem Klevtsov's avatar Artem Klevtsov 😹

Use self-writen library

parent 631e3199
Pipeline #120265538 passed with stages
in 8 minutes and 49 seconds
......@@ -5,4 +5,7 @@
src/*.o
src/*.so
src/*.dll
src/Makevars
config.log
config.status
tmp
......@@ -10,12 +10,10 @@ Authors@R: c(
comment = c(ORCID = "0000-0003-0492-6647"))
)
Description: Provides funstion to generating a vector of Universally Unique Identifiers
(UUID) version 4. Based on the sole C++ library <https://github.com/r-lyeh-archived/sole>.
Used the OpenMP library to improve performance.
(UUID) version 4. Used the OpenMP library to improve performance.
URL: https://artemklevtsov.gitlab.io/rcppuuid, https://gitlab.com/artemklevtsov/rcppuuid
BugReports: https://gitlab.com/artemklevtsov/rcppuuid/issues
License: GPL (>= 2)
Copyright: file COPYRIGHTS
Imports: Rcpp (>= 1.0.3)
Suggests: tinytest (>= 1.1.0), uuid, microbenchmark
LinkingTo: Rcpp
......
Condition of use
----------------
Please see the included file COPYRIGHTS for per-file details on licenses
as well as copyrights and more specifically the file COPYRIGHTS in the inst
directory.
sole library (as an upstram project) is licensed under zlib
License.
RcppUUID package is licensed under GNU General Public License version
2 or later.
Some part of the Rcpp package have been adapted to the uchardet pacakge.
Rcpp is publicly available under the GNU General Public license version 2 or
higher.
......@@ -2,8 +2,7 @@
#'
#' @description
#' Provides funstion to generating a vector of Universally Unique Identifiers
#' (UUID) version 4. Based on the sole C++ library <https://github.com/r-lyeh-archived/sole>.
#' Used the OpenMP library to improve performance.
#' (UUID) version 4. Used the OpenMP library to improve performance.
#'
#' @name RcppUUID
#' @docType package
......
......@@ -24,7 +24,7 @@ knitr::opts_chunk$set(
<!-- badges: end -->
R package to generate Universally Unique Identifiers (UUIDs) version 4. Based on the [sole](https://github.com/r-lyeh-archived/sole) C++ library.
R package to generate Universally Unique Identifiers (UUIDs) version 4.
## Installation
......
......@@ -19,8 +19,6 @@ v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://www.gnu.org
<!-- badges: end -->
R package to generate Universally Unique Identifiers (UUIDs) version 4.
Based on the [sole](https://github.com/r-lyeh-archived/sole) C++
library.
## Installation
......@@ -47,18 +45,18 @@ Generate single UUID:
``` r
RcppUUID::uuid_generate(1)
#> [1] "1700a888-a7c5-4dd4-9aad-a98128279f87"
#> [1] "3037a109-1f65-4f34-ac60-69730596442d"
```
Generate multiple UUIDs:
``` r
RcppUUID::uuid_generate(5)
#> [1] "04c01dc0-299d-461e-9b56-2f881376f445"
#> [2] "b18beaf4-b27c-4fed-a93c-08f80feb1fcf"
#> [3] "29e2778d-7b5b-4128-9184-3865953c69f0"
#> [4] "818d0636-d854-44a3-ab43-6fb9bbb60e40"
#> [5] "a09697a7-5cc5-41b3-86b3-07ba50bf8cd3"
#> [1] "7fc1fbfb-b050-4a5d-acfc-c03094c7f131"
#> [2] "af7c0750-dc5d-410b-867a-38c66218ceaf"
#> [3] "b37fedc9-3af5-444b-9ad8-b188cceb6e60"
#> [4] "1a68b7e7-c110-4c8b-9e45-3c9029e37ac8"
#> [5] "579dc2f1-8c38-4b9a-ba0a-e28427d6e184"
```
Check uniques:
......@@ -79,9 +77,9 @@ microbenchmark::microbenchmark(
RcppUUID = RcppUUID::uuid_generate(1)
)
#> Unit: microseconds
#> expr min lq mean median uq max neval cld
#> uuid 15.221 16.270 59.07903 17.5115 18.4200 4167.623 100 a
#> RcppUUID 13.318 44.686 163.90026 65.0965 95.2315 6306.544 100 a
#> expr min lq mean median uq max neval cld
#> uuid 15.323 16.1925 39.53524 17.6065 18.4155 2198.415 100 a
#> RcppUUID 48.332 52.5675 130.83716 60.1960 72.5415 6177.065 100 a
```
Multiple UUIDs:
......@@ -93,9 +91,9 @@ microbenchmark::microbenchmark(
RcppUUID = RcppUUID::uuid_generate(n)
)
#> Unit: milliseconds
#> expr min lq mean median uq max neval cld
#> uuid 179.76032 200.29648 225.46853 215.11818 237.76798 410.55628 100 b
#> RcppUUID 17.10199 19.23641 21.17651 20.07005 21.28216 42.02892 100 a
#> expr min lq mean median uq max neval cld
#> uuid 180.05588 194.97129 229.71894 217.38809 243.4737 432.34116 100 b
#> RcppUUID 47.21502 48.92965 52.58226 50.83771 54.1418 80.33077 100 a
```
## Bug reports
......
#!/bin/sh
rm -f config.* src/Makevars src/snappy/snappy-stubs-public.h
rm -rf autom4te.cache
This diff is collapsed.
AC_PREREQ([2.69])
AC_INIT([RcppUUID],m4_esyscmd_s([awk '/^Version:/ {print $2}' DESCRIPTION]),[a.a.klevtsov@gmail.com])
AC_CONFIG_SRCDIR([src/RcppExports.cpp])
dnl find R home and set correct compiler + flags
if test -z "${R_HOME}" ; then
R_HOME=`R RHOME`
fi
AC_MSG_CHECKING([R_HOME])
if test -z "${R_HOME}"; then
AC_MSG_RESULT([No])
AC_MSG_ERROR([Can not find ${R_HOME}.])
fi
AC_MSG_RESULT([${R_HOME}])
R_BIN="${R_HOME}/bin/R"
dnl pick all flags for testing from R
CC=`"${R_BIN}" CMD config CC`
CPP=`"${R_BIN}" CMD config CPP`
CXX=`"${R_BIN}" CMD config CXX`
CFLAGS=`"${R_BIN}" CMD config CFLAGS`
CPPFLAGS=`"${R_BIN}" CMD config CPPFLAGS`
LDFLAGS=`"${R_BIN}" CMD config LDFLAGS`
AC_PROG_CC(${CC})
AC_PROG_CPP(${CPP})
AC_PROG_CXX(${CXX})
AC_REQUIRE_CPP
AC_LANG(C++)
host_os=`uname -s`
case "${host_os}" in
Darwin*)
PKG_CPPFLAGS=-DGUID_CFUUID
PKG_LIBS=-Wl,-S
;;
Linux*)
AC_CHECK_HEADER([uuid/uuid.h],LIBUUID_HEADER=yes)
AC_CHECK_LIB([uuid],[uuid_generate],LIBUUID_LIB=yes)
if test "x${LIBUUID_HEADER}" = "xyes" && test "x${LIBUUID_LIB}" = "xyes"; then
PKG_CPPFLAGS=-DGUID_LIBUUID
PKG_LIBS="-Wl,-S -luuid"
else
PKG_CPPFLAGS=-DGUID_RANDOM
fi
;;
SunOS*)
AC_CHECK_HEADER([uuid/uuid.h],LIBUUID_HEADER=yes)
AC_CHECK_LIB([uuid],[uuid_generate],LIBUUID_LIB=yes)
if test "x${LIBUUID_HEADER}" = "xyes" && test "x${LIBUUID_LIB}" = "xyes"; then
PKG_CPPFLAGS=-DGUID_LIBUUID
PKG_LIBS=-luuid
else
PKG_CPPFLAGS=-DGUID_RANDOM
fi
;;
*)
PKG_CPPFLAGS=-DGUID_RANDOM
;;
esac
AC_MSG_NOTICE([OS: ${host_os}])
AC_MSG_NOTICE([CC: ${CC}])
AC_MSG_NOTICE([CPP: ${CPP}])
AC_MSG_NOTICE([CXX: ${CXX}])
AC_MSG_NOTICE([PKG_CPPFLAGS: ${PKG_CPPFLAGS}])
AC_MSG_NOTICE([PKG_LIBS: ${PKG_LIBS}])
AC_MSG_NOTICE([${PACKAGE_NAME}: ${PACKAGE_VERSION}])
AC_SUBST([PKG_CPPFLAGS])
AC_SUBST([PKG_LIBS])
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT
Overall license:
================
All package files are released under the GNU General Public License version 2.
The ced package based on the original Compact Encoding Detection software by Google (https://github.com/google/compact_enc_det). Local version is situated in the src/compact_enc_det folder.
Details:
========
Files: *
Copyright: (c) 2020 Artem Klevtsov
License: GPL-2
Original Location: https://gitlab.com/artemklevtsov/rcppuuid
Files: inst/include/sole.hpp
Copyright: (c) 2015 r-lyeh (https://github.com/r-lyeh)
License: zlib License
Original Location: https://github.com/r-lyeh-archived/sole
This diff is collapsed.
#pragma once
#include <array>
#include <string>
#include <sstream>
#include <utility>
#include <iterator>
#include <iomanip>
#ifdef GUID_LIBUUID
#include <uuid/uuid.h>
#elif GUID_WINDOWS
#include <objbase.h>
#elif GUID_CFUUID
#include <CoreFoundation/CFUUID.h>
#elif GUID_RANDOM
#include <algorithm>
#include <functional>
#include <random>
#endif
/*
* UUID class
*/
class uuid {
public:
using value_t = unsigned char;
using data_t = std::array<value_t, 16>;
constexpr uuid() noexcept : data({}) {};
uuid(const data_t& arr) noexcept {
std::copy(std::begin(arr), std::end(arr), std::begin(data));
}
void swap(uuid& other) noexcept {
data.swap(other.data);
}
private:
data_t data{{ 0 }};
friend std::ostream &operator<<(std::ostream& s, const uuid& id);
};
std::ostream &operator<<(std::ostream &s, const uuid& id) {
std::ios_base::fmtflags f(s.flags());
s << std::hex << std::setfill('0')
<< std::setw(2) << static_cast<int>(id.data[0])
<< std::setw(2) << static_cast<int>(id.data[1])
<< std::setw(2) << static_cast<int>(id.data[2])
<< std::setw(2) << static_cast<int>(id.data[3])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[4])
<< std::setw(2) << static_cast<int>(id.data[5])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[6])
<< std::setw(2) << static_cast<int>(id.data[7])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[8])
<< std::setw(2) << static_cast<int>(id.data[9])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[10])
<< std::setw(2) << static_cast<int>(id.data[11])
<< std::setw(2) << static_cast<int>(id.data[12])
<< std::setw(2) << static_cast<int>(id.data[13])
<< std::setw(2) << static_cast<int>(id.data[14])
<< std::setw(2) << static_cast<int>(id.data[15]);
s.flags(f);
return s;
}
std::string to_string(const uuid& id) {
std::stringstream ss;
ss << id;
return ss.str();
}
/*
* UUID generator class
*/
class uuid_generator {
public:
using value_t = unsigned char;
using data_t = std::array<value_t, 16>;
uuid operator()() {
#ifdef GUID_LIBUUID
uuid_t id;
uuid_generate(id);
data_t res = {
id[0],
id[1],
id[2],
id[3],
id[4],
id[5],
id[6],
id[7],
id[8],
id[9],
id[10],
id[11],
id[12],
id[13],
id[14],
id[15]
};
return uuid{std::move(res)};
#elif GUID_WINDOWS
GUID id;
CoCreateGuid(&id);
data_t res = {
static_cast<unsigned char>(((id.Data1 >> 24) & 0xFF)),
static_cast<unsigned char>(((id.Data1 >> 16) & 0xFF)),
static_cast<unsigned char>(((id.Data1 >> 8) & 0xFF)),
static_cast<unsigned char>(((id.Data1) & 0xff)),
static_cast<unsigned char>(((id.Data2 >> 8) & 0xFF)),
static_cast<unsigned char>(((id.Data2) & 0xff)),
static_cast<unsigned char>(((id.Data3 >> 8) & 0xFF)),
static_cast<unsigned char>(((id.Data3) & 0xFF)),
static_cast<unsigned char>(id.Data4[0]),
static_cast<unsigned char>(id.Data4[1]),
static_cast<unsigned char>(id.Data4[2]),
static_cast<unsigned char>(id.Data4[3]),
static_cast<unsigned char>(id.Data4[4]),
static_cast<unsigned char>(id.Data4[5]),
static_cast<unsigned char>(id.Data4[6]),
static_cast<unsigned char>(id.Data4[7])
};
return uuid{std::move(res)};
#elif GUID_CFUUID
auto id = CFUUIDCreate(NULL);
auto bytes = CFUUIDGetUUIDBytes(id);
CFRelease(id);
data_t res = {
bytes.byte0,
bytes.byte1,
bytes.byte2,
bytes.byte3,
bytes.byte4,
bytes.byte5,
bytes.byte6,
bytes.byte7,
bytes.byte8,
bytes.byte9,
bytes.byte10,
bytes.byte11,
bytes.byte12,
bytes.byte13,
bytes.byte14,
bytes.byte15
};
return uuid{std::move(res)};
#elif GUID_RANDOM
std::uniform_int_distribution<uint32_t> distribution;
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uint8_t bytes[16];
for (int i = 0; i < 16; i += 4) {
*reinterpret_cast<uint32_t*>(bytes + i) = distribution(generator);
}
// variant must be 10xxxxxx
bytes[8] &= 0xBF;
bytes[8] |= 0x80;
// version must be 0100xxxx
bytes[6] &= 0x4F;
bytes[6] |= 0x40;
data_t res = {
bytes[0],
bytes[1],
bytes[2],
bytes[3],
bytes[4],
bytes[5],
bytes[6],
bytes[7],
bytes[8],
bytes[9],
bytes[10],
bytes[11],
bytes[12],
bytes[13],
bytes[14],
bytes[15]
};
return uuid{std::move(res)};
#endif
}
};
......@@ -7,8 +7,7 @@
\title{Generating Universally Unique Identificators}
\description{
Provides funstion to generating a vector of Universally Unique Identifiers
(UUID) version 4. Based on the sole C++ library <https://github.com/r-lyeh-archived/sole>.
Used the OpenMP library to improve performance.
(UUID) version 4. Used the OpenMP library to improve performance.
}
\seealso{
Useful links:
......
PKG_CPPFLAGS = -I../inst/include
PKG_CPPFLAGS = -I../inst/include @PKG_CPPFLAGS@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = @PKG_LIBS@ $(SHLIB_OPENMP_CXXFLAGS)
CXX_STD = CXX11
PKG_CPPFLAGS = -I../inst/include -fpermissive
PKG_CPPFLAGS = -I../inst/include -DGUID_WINDOWS
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = -lole32 $(SHLIB_OPENMP_CXXFLAGS)
CXX_STD = CXX11
#include <sole.hpp>
#include <uuid.h>
#include <Rcpp.h>
//' @title
......@@ -21,8 +21,8 @@ std::vector<std::string> uuid_generate(size_t n = 1) {
std::vector<std::string> res(n);
#pragma omp parallel for
for (size_t i = 0; i < n; ++i) {
sole::uuid id = sole::uuid4();
res[i] = id.str();
uuid id = uuid_generator{}();
res[i] = to_string(id);
}
return res;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment