Skip to content

Instantly share code, notes, and snippets.

@lvpidadiao
lvpidadiao / floor_ceil_power_2.cpp
Created January 3, 2020 10:11
floor or ceil power of 2
inline constexpr uint32_t ceilPowerOfTwo(uint32_t num) {
num |= (num >> 1);
num |= (num >> 2);
num |= (num >> 4);
num |= (num >> 8);
num |= (num >> 16);
return num - (num >> 1);
}
inline constexpr uint32_t roundupPowerOfTwo(uint32_t num) {
@lvpidadiao
lvpidadiao / template selector.cpp
Created October 18, 2019 08:02
simple selector
class connbase {
public:
virtual void Send() = 0;
};
typedef enum {
WithEnc,
WithoutEnc
}enc;
@lvpidadiao
lvpidadiao / bytes_buf.cpp
Created October 15, 2019 06:52
simple bytes buf。with extend and noextend buffer, also the buffer could managed by yourself。
//
// Created by TrevorProfessor on 2019-09-18.
//
#include <cstring>
#include "bytes_buf.hpp"
static int align128(int v) {
#define CACHE_LINE_SIZE 128