Skip to content

Instantly share code, notes, and snippets.

@nemerle
nemerle / storeBinTree.cpp
Last active April 10, 2018 15:57
bintree packing code
static int storeBinTreesResult(BitStream &bs,const std::array<bintree_in,7> &bintree)
{
// this least means that midpoint ( idx 0 ) depends on midpoint, but that's check with idx==0
// then checking S - * - M - - - E (idx 1) depends on actual midpoint, and we check it
// then checking S - - - M - * - E (idx 2) same as above
// then checking S * - - M - - - E (idx 3) checking that we had SM/2 midpoint
// then checking S - - * M - - - E (idx 4) checking that we had SM/2 midpoint
// ...
static const uint8_t dependency_indices[] = {0,0,0,1,1,2,2};
static const uint8_t tree_depth_bits_mod[8] = { 1,2,2,3,3,3,3 };
@nemerle
nemerle / CallMapper.hpp
Last active December 15, 2015 11:39
C++11 MRuby template based ruby->c++ call mapper and structure bind class;
/*
The CallMapper::extract_args_and_call works like this:
It builds a tuple whose members are based on types of arguments of the passed in 'func'
After that, for each tuple member, it calls appropriate extract_arg function to fill that particular tuple member.
When all members are extracted, it calls the func with 'unpacked' tuple.
*/
struct CallMapper {
/*
Ruby arg format chars
o - Object