Coder Social home page Coder Social logo

p-ranav / oystr Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 879 KB

oystr recursively searches directories for a substring.

License: MIT License

C++ 71.28% CMake 28.72%
cli command-line search cpp17 grep grep-like mit-license modern-cpp oystr recursively-search

oystr's Introduction

oystr

oystr is a command-line tool that recursively searches directories for a substring.

Quick Start

Build oystr using CMake. For more details, see BUILDING.md.

git clone https://github.com/p-ranav/oystr
cd oystr

# Build
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build

# Install
sudo cmake --install build

oystr's People

Contributors

p-ranav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oystr's Issues

Use AVX2 needle search for case sensitive scenarios

#include <immintrin.h>

const char* find_avx2_more(const char* b, const char* e, char c)
{
  const char* i = b;

  __m256i q = _mm256_set1_epi8(c);

  for (; i + 32 < e; i += 32) {
    __m256i x = _mm256_lddqu_si256(reinterpret_cast<const __m256i*>(i));
    __m256i r = _mm256_cmpeq_epi8(x, q);
    int z = _mm256_movemask_epi8(r);
    if (z)
      return i + __builtin_ffs(z) - 1;
  }
  if (i < e) {
    if (e - b < 32) {
      for (; i < e; ++i)
        if (*i == c)
          return i;
    } else {
      i = e - 32;
      __m256i x = _mm256_lddqu_si256(reinterpret_cast<const __m256i*>(i));
      __m256i r = _mm256_cmpeq_epi8(x, q);
      int z = _mm256_movemask_epi8(r);
      if (z)
        return i + __builtin_ffs(z) - 1;
    }
  }
  return e;
}

auto needle_search_avx2(std::string_view needle,
                        std::string_view::const_iterator haystack_begin,
                        std::string_view::const_iterator haystack_end,
                        bool ignore_case)
{
  if (needle.empty()) {
    return haystack_end;
  }
  const char c = needle[0];

  // quickly find c in haystack
  auto it = haystack_begin;
  while (it != haystack_end) {
    const char* ptr = find_avx2_more(it, haystack_end, c);
    bool result = true;

    const char* i = ptr;
    for (auto& n : needle) {
      if (n != *i) {
        result = false;
        break;
      }
      i++;
    }

    if (result) {
      return ptr;
    } else {
      it = i;
    }
  }

  return haystack_end;
}

Search fails in small file

bob@LAPTOP-JDRTARVO:~/dev/search$ time grep -irn 'qmi' ../quectel-CM/NOTICE
3:The APIs of QMI WWAMN interfaces are defined by Qualcomm. And this program complies with Qualcomm QMI WWAN interfaces specification.

real    0m0.002s
user    0m0.002s
sys     0m0.000s
bob@LAPTOP-JDRTARVO:~/dev/search$ time ./build/search -irn 'qmi' ../quectel-CM/NOTICE

real    0m0.002s
user    0m0.002s
sys     0m0.001s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.