logo
down
shadow

Whats the fastest, portable way to hash pointers we know are pointer aligned to a fixed size int?


Whats the fastest, portable way to hash pointers we know are pointer aligned to a fixed size int?

By : Sri Ningsih
Date : November 22 2020, 07:01 PM
wish help you to fix your issue When mod math is fast, a quick hash is to mod by a prime <= TARGET_TYPE_MAX. The mod will use all the bits of the p to form the hash.
By using the largest prime, only a few buckets are lost, but speed is the goal.
code :
#define LARGEST_PRIME8 251u
#define LARGEST_PRIME15 32749u
#define LARGEST_PRIME16 65521u
#define LARGEST_PRIME31 2147483647u
#define LARGEST_PRIME32 4294967291u
#define LARGEST_PRIME63 9223372036854775783u
#define LARGEST_PRIME64 18446744073709551557u

uint32_t hash = (uint32_t) ((uintptr_t)(void *)p) % LARGEST_PRIME32);


Share : facebook icon twitter icon
Fastest method on x86-64 to check if pointer range straddles an N byte aligned address?

Fastest method on x86-64 to check if pointer range straddles an N byte aligned address?


By : P Tuan
Date : March 29 2020, 07:55 AM
This might help you Given a pointer to a T, I'd like to determine if the T straddles an N byte aligned address. In practice I really only care about whether 0-5 byte size objects straddle 8 or 16 byte byte boundaries, but I wrote up this general version: , You could do:
code :
unsigned long offset = (unsigned long)obj & (N-1);
return offset > N - sizeof(T);
Is it possible to hash pointers in portable C++03 code?

Is it possible to hash pointers in portable C++03 code?


By : Aung Myo Kyaw
Date : March 29 2020, 07:55 AM
hop of those help? No, in general. In fact it's not even possible in general in C++11 without std::hash.
The reason why lies in the difference between values and value representations.
code :
int i;
int* x = &i;
int* y = &i;

x == y;  // this is true; the two pointer values are equal
struct __pointer_impl
{
    std::uint8_t byte1; // contains the address we're holding
    std::uint8_t byte2; // needed for architecture reasons, unused
    // (assume no padding; we are the compiler, after all)
};
bool operator==(const __pointer_impl& first, const __pointer_impl& second)
{
    return first.byte1 == second.byte1;
}
__pointer_impl address_of(int& i)
{
    __pointer_impl result;

    result.byte1 = /* hypothetical architecture magic */;

    return result;
}
int i;

/* int* x = &i; */
__pointer_impl x = __address_of(i);

/* int* y = &i; */
__pointer_impl y = __address_of(i);

x == y;  // this is true; the two pointer values are equal
template <typename T>
struct myhash;

template <typename T>
struct myhash<T*> :
    std::unary_function<T*, std::size_t>
{
    std::size_t operator()(T* const ptr) const
    {
        return /* ??? */;
    }
};
return myhash<std::uintptr_t>()(reinterpret_cast<std::uintptr_t>(ptr));
// okay because we assumed no padding:
typedef std::uint16_t __uintptr_t; // will be used for std::uintptr_t implementation

__uintptr_t __to_integer(const __pointer_impl& ptr)
{
    __uintptr_t result;
    std::memcpy(&result, &ptr, sizeof(__uintptr_t));

    return result;
}

__pointer_impl __from_integer(const __uintptr_t& ptrint)
{
    __pointer_impl result;
    std::memcpy(&result, &ptrint, sizeof(__pointer_impl));

    return result;
}
What is the fastest hash function for pointers?

What is the fastest hash function for pointers?


By : Alyssa Mazzina
Date : March 29 2020, 07:55 AM
I wish this help you After letting this question lay for a while, I'll post my best hash function for pointers so far:
code :
template<typename Tval>
struct MyTemplatePointerHash1 {
    size_t operator()(const Tval* val) const {
        static const size_t shift = (size_t)log2(1 + sizeof(Tval));
        return (size_t)(val) >> shift;
    }
};
Why can't I pass the address of a pointer to a fixed size array into a function expecting a pointer to a pointer in C?

Why can't I pass the address of a pointer to a fixed size array into a function expecting a pointer to a pointer in C?


By : jeffwiedenfeld
Date : March 29 2020, 07:55 AM
it helps some times You're making the mistake of believing a pointer and an array are the same things. They are not. They can be used in the same way (which is completely different from saying "they are the same thing") in some contexts but not others. Your examples are in contexts in which pointers and arrays are different things, and cannot be used as if they are the same thing.
In your first case, passing foo to singleLeftPadZero() works by first performing an "array to pointer conversion" - foo is an array of ten char, and is converted to a pointer of type char * with value equal to &foo[0]. A char * is not a char **, hence the warning about incompatible type and the note.
c/c++ data type with fastest portable access by pointer?

c/c++ data type with fastest portable access by pointer?


By : SILAR SHAH
Date : March 29 2020, 07:55 AM
I wish this help you I think you should not bother that much, and the details depend upon the compiler, the optimization flags, the processor.
Don't forget that premature optimization is evil.
Related Posts Related Posts :
  • C error conflicting types
  • How do I convert text to XML in C?
  • Call by Reference Function
  • C programming XML
  • Reading a directory
  • C error Array: array type has incomplete element type.
  • Compiling C code in Windows XP
  • Is there any char to hexadecimal function for C?
  • c compilation error
  • 5x5 matrix multiplication in C
  • parent process, and a child process
  • Linked list recursive reverse
  • C warning conflicting types
  • how to print a char from struct
  • dynamic memory for 2D char array
  • C compiler producing lightweight executeables
  • Cannot Open Shared Object cygmpfr-1.dll
  • How to access a structure member in a function that get it as void* type?
  • Replace for loop with formula
  • how to find if stack increases upwards or downwards?
  • Why does my homespun sizeof operator need a char* cast?
  • Setting exit status when creating core dump
  • Signal Handling in C
  • How to implement B+ Tree for file systems?
  • Stack storage at function call
  • Manipulate the Clipboard in C on Mac OS X
  • Problem with writing a hexadecimal string
  • Why does this code read all ' ' for the anything after the 4th character?
  • GUI for linux c
  • Where do I put all these function-like #defines, in C?
  • Padding in 24-bits rgb bitmap
  • how to acess and change variable of kernel space from user space
  • Can a conforming C implementation #define NULL to be something wacky
  • send() always interrupted by EPIPE
  • Socket Select with empty fd set
  • Coding self similar fractals in computer graphics using C
  • Forking with Pipes
  • sscanf + c99 not working on some platforms?
  • Problem with C function of type char pointer, can someone explain?
  • Macros in C.... please give the solution
  • Unix Piping using Fork and Dup
  • Any difference between these two while loops?
  • Hashtable implementation for C
  • Problems with Linked List in C
  • Stack Allocation in C
  • Random function stuck on one number
  • printf following zeros to a certain degree
  • Measuring CPU clocks consumed by a process
  • How is a CRC32 checksum calculated?
  • Tips on redefining a register bitfield in C
  • Converting a program from c to bash script
  • Static library not included in resulting LLVM executable
  • What is the meaning of "wild pointer" in C?
  • Reading DWORD from binary file
  • Efficient way to find divisibility
  • Why does my summation program behaves weird?
  • How to determine values saved on the stack?
  • Thread scheduling C
  • C - converting to 2s complement
  • wireless networks c program
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk