Coder Social home page Coder Social logo

bbondy / hashset-cpp Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 19.0 160 KB

Simple hashtable implementation with easy serialization and deserialization

License: Mozilla Public License 2.0

C++ 72.50% Makefile 1.72% Python 23.37% JavaScript 0.17% C 2.24%

hashset-cpp's Introduction

Hash Set

Build Status

Implements a simple HashSet for strings in environments where you don't have the std lib available. You should probably not be using this. Instead consider using hash_set which is a more generic implementation with templates. This is only useful for very specific use cases having specific memory layout requirements.

Setup

npm install --save hashset-cpp

Sample

#include <iostream>
#include "hash_set.h"
#include "test/example_data.h"

using std::cout;
using std::endl;

int main(int argc, char **argv) {
  // Bucket size is 256 and don't allow multiple items per item hash.
  HashSet<ExampleData> set(256, false);
  set.Add(ExampleData("test"));

  // Prints true
  cout << "test exists: " << (set.Exists(ExampleData("test"))
      ? "true" : "false") << endl;
  // Prints false
  cout << "test2 exists: " << (set.Exists(ExampleData("test2"))
      ? "true" : "false") << endl;

  uint32_t len;
  char * buffer = set.Serialize(&len);
  HashSet<ExampleData> set2(0, false);
  set2.Deserialize(buffer, len);
  // Prints true
  cout << "test exists: " << (set2.Exists(ExampleData("test"))
      ? "true" : "false") << endl;
  // Prints false
  cout << "test2 exists: " << (set2.Exists(ExampleData("test2"))
      ? "true" : "false") << endl;

  delete[] buffer;
  return 0;
}

Build everything in release

make

Running sample

make sample

Running tests

make test

Clearing build files

make clean

Linting

npm run lint

hashset-cpp's People

Contributors

bbondy avatar bridiver avatar dependabot[bot] avatar emerick avatar mailtokartik1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

hashset-cpp's Issues

Error during install / make: "no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?"

Install fails on macos with

ecef7bbf -mllvm -disable-aligned-alloc-awareness=1 -mllvm -enable-dse-memoryssa=0 -o Release/obj.target/hashset-cpp/addon.o -x c++ ../addon.cc
npm ERR! clang -cc1 version 13.0.0 (clang-1300.0.29.30) default target arm64-apple-darwin21.4.0
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/src"
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/deps/openssl/config"
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/deps/openssl/openssl/include"
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/deps/uv/include"
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/deps/zlib"
npm ERR! ignoring nonexistent directory "/Users/petemill/.node-gyp/16.14.0/deps/v8/include"
npm ERR! ignoring nonexistent directory "/usr/local/include"
npm ERR! ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
npm ERR! ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
npm ERR! #include "..." search starts here:
npm ERR! #include <...> search starts here:
npm ERR!  /Users/petemill/.node-gyp/16.14.0/include/node
npm ERR!  ../.
npm ERR!  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
npm ERR!  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include
npm ERR!  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
npm ERR!  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
npm ERR!  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
npm ERR! End of search list.
npm ERR! In file included from ../addon.cc:6:
npm ERR! In file included from /Users/petemill/.node-gyp/16.14.0/include/node/node.h:63:
npm ERR! In file included from /Users/petemill/.node-gyp/16.14.0/include/node/v8.h:30:
npm ERR! /Users/petemill/.node-gyp/16.14.0/include/node/v8-internal.h:492:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
npm ERR!             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                 ~~~~~^~~~~~~~~~~
npm ERR!                                      remove_cv
npm ERR! /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:710:50: note: 'remove_cv' declared here
npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
npm ERR!                                                  ^
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/hashset-cpp/addon.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2

Build fails on MacOS 10.13.4 / node 10.3.0

Hey Bondy,

same issue as with bloom-filter-cpp, care to fix? I don't have the C++ skills, otherwise I'd create a PR myself.

Related issue from bloom-filter-cpp is here: bbondy/bloom-filter-cpp#4

Issue:

../hash_set_wrap.cc:61:37: error: no matching member function for call to 'NewInstance'
    args.GetReturnValue().Set(cons->NewInstance(argc, argv));
                              ~~~~~~^~~~~~~~~~~

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.