Code Monkey home page Code Monkey logo

gtl's People

Contributors

greg7mdp avatar phprus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtl's Issues

Undefined behavior in phmap_utils.hpp

reinterpret_cast from float* to uint*_t* is UB (break strict aliasing).

Suggestions:

gtl/gtl/phmap_utils.hpp

Lines 268 to 271 in 76382cc

// -0.0 and 0.0 should return same hash
uint32_t *as_int = reinterpret_cast<uint32_t *>(&val);
return (val == 0) ? static_cast<size_t>(0) :
static_cast<size_t>(*as_int);

        uint32_t as_int;
        std::memcpy(&as_int, &val, sizeof(as_int));
        return (val == 0) ? static_cast<size_t>(0) :
                            static_cast<size_t>(as_int);

and

gtl/gtl/phmap_utils.hpp

Lines 280 to 283 in 76382cc

// -0.0 and 0.0 should return same hash
uint64_t *as_int = reinterpret_cast<uint64_t *>(&val);
return (val == 0) ? static_cast<size_t>(0) :
fold_if_needed<sizeof(size_t)>()(*as_int);

        uint64_t as_int;
        std::memcpy(&as_int, &val, sizeof(as_int));
        return (val == 0) ? static_cast<size_t>(0) :
                            fold_if_needed<sizeof(size_t)>()(as_int);

Proposal: Remove duplication of standard declarations

I am trying to remove duplicate and unused code in gtl.
Current state: https://github.com/phprus/gtl/tree/todo-1

I don't understand the need for declarations:

template <class T> struct EqualTo;
template <class T> struct Less;
template <class T> using Allocator = typename std::allocator<T>;
template<class T1, class T2> using Pair = typename std::pair<T1, T2>;

and

// type alias for std::allocator so we can forward declare without including other headers
template <class T>
using Allocator = typename gtl::Allocator<T>;
// type alias for std::pair so we can forward declare without including other headers
template<class T1, class T2>
using Pair = typename gtl::Pair<T1, T2>;

and

template <class T> using Allocator = typename std::allocator<T>;
template<class T1, class T2> using Pair = typename std::pair<T1, T2>;
template <class T>
struct EqualTo
{
inline bool operator()(const T& a, const T& b) const
{
return std::equal_to<T>()(a, b);
}
};
template <class T>
struct Less
{
inline bool operator()(const T& a, const T& b) const
{
return std::less<T>()(a, b);
}
};

Maybe replace these definitions with using std::allocator, std::pair, std::equal_to, std::less directly?

Benchmark

Hi,

What's the use case for this library? Please add benchmarks against original implementation so that we can understand if this is faster.

multimap

Greg,
Do you have plans to add a multimap variant for your flat hash map?

Feature Request: steal backing array in flat map/set

One feature that would greatly decrease peak memory usage in my use-case is to have the ability to "steal" the backing array from the flat-maps (after compacting them into a "normal" array first of course.)

The use-case is currently implemented as follows:

  1. add / update many objects in a flat_hash_set
  2. allocate a new array, iterate over the flat_hash_set, adding all to the array
  3. delete the flat_hash_set
  4. sort the array of objects

Perhaps something along the lines of:

// Removes and returns an array of all entries in the set.  Optimized implementations may re-use an internal array, thus
// lowering memory usage.  Only the first size() entries are defined.  It is the callers responsibility to delete the returned array.
value_type* remove_all_entries()

Oh, and thank you for the inspired lazy_emplace()! It's still more powerful than other map/set implementations of try_emplace since key creation can be deferred or customized as well.

Empty functions

The header file phmap.hpp contains empty functions:

gtl/include/gtl/phmap.hpp

Lines 662 to 707 in 8471500

// ----------------------------------------------------------------------------
// I N F O Z S T U B S
// ----------------------------------------------------------------------------
struct HashtablezInfo
{
void PrepareForSampling() {}
};
inline void RecordRehashSlow(HashtablezInfo*, size_t ) {}
static inline void RecordInsertSlow(HashtablezInfo* , size_t, size_t ) {}
static inline void RecordEraseSlow(HashtablezInfo*) {}
static inline HashtablezInfo* SampleSlow(int64_t*) { return nullptr; }
static inline void UnsampleSlow(HashtablezInfo* ) {}
class HashtablezInfoHandle
{
public:
inline void RecordStorageChanged(size_t , size_t ) {}
inline void RecordRehash(size_t ) {}
inline void RecordInsert(size_t , size_t ) {}
inline void RecordErase() {}
friend inline void swap(HashtablezInfoHandle& ,
HashtablezInfoHandle& ) noexcept {}
};
static inline HashtablezInfoHandle Sample() { return HashtablezInfoHandle(); }
class HashtablezSampler
{
public:
// Returns a global Sampler.
static HashtablezSampler& Global() { static HashtablezSampler hzs; return hzs; }
HashtablezInfo* Register() { static HashtablezInfo info; return &info; }
void Unregister(HashtablezInfo* ) {}
using DisposeCallback = void (*)(const HashtablezInfo&);
DisposeCallback SetDisposeCallback(DisposeCallback ) { return nullptr; }
int64_t Iterate(const std::function<void(const HashtablezInfo& stack)>& ) { return 0; }
};
static inline void SetHashtablezEnabled(bool ) {}
static inline void SetHashtablezSampleParameter(int32_t ) {}
static inline void SetHashtablezMaxSamples(int32_t ) {}

Some of these functions are not used anywhere.

Please tell me, are these functions needed or can they be removed?

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.