Skip to content

Instantly share code, notes, and snippets.

View kingsamchen's full-sized avatar
🐛
Work life balance

0xCCCCCCCC kingsamchen

🐛
Work life balance
View GitHub Profile
@kingsamchen
kingsamchen / type_traits_demo.cpp
Last active December 16, 2015 12:09
demo for traits implementation
struct built_in_type_tag{};
struct integer_type_tag : public built_in_type_tag {};
struct user_defined_type_tag{};
template<typename TypeT>
struct type_traits
{
typedef typename TypeT::type_category type_category;
};
template<typename T>
class NewHandlerSupport
{
public:
static std::new_handler set_new_handler(std::new_handler p) throw();
static void* operator new(std::size_t size) throw(std::bad_alloc);
...
private:
static std::new_handler currentHandler;
};
@kingsamchen
kingsamchen / ichar_traits.cpp
Created May 14, 2013 03:16
user_defined stl::basic_string traits
using std::basic_string;
using std::char_traits;
using std::string;
using std::toupper;;
struct ichar_traits : char_traits<char>
{
static bool eq(const char& _Left, const char& _Right)
{
return toupper(_Left) == toupper(_Right);
#include <cassert>
#include <cstdio>
#define PARENT(x) (((x) - 1) >> 1)
#define LEFTCHILD(x) (((x) << 1) + 1)
#define RIGHTCHILD(x) (((x) + 1) << 1)
template<typename T>
class CPriQueue
{
class NLComponent
{
public:
virtual NLComponent* clone() const = 0;
};
class TextBlocks : public NLComponent
{
public:
// only a single object allowed
struct PrintJob
{
PrintJob(const string& name) : Name(name)
{
}
string Name;
};
class Printer

original tabu Search

  1. determine the next move
  2. add the move into tabu list with a specified tabu iteration count in order to avoid cycling.
  3. aspiration strategy allowed if a move, despite in tabu, generates a better result than ever been.

robust tabu search

I. (seemingly) slight differences in general tactics

//// C#
class SeqTest
{
string _inClassName;
public string InClassName
{
get {return _inClassName;}
set {_inClassName = value;}
def SolveLinearEquationSystem(coeffMatrix, valVector):
# create the augmented matrix
augMatrix = []
for i in range(0, len(coeffMatrix)):
augMatrix.append(coeffMatrix[i] + [valVector[i]])
for i in range(0, len(augMatrix) - 1):
# find row containing largest ith col ele then swap with row i
# ensure scaling factor will never exceed 1
# otherwise, round-off error may be bring about due to different magnitude order
@kingsamchen
kingsamchen / csapp_exer_2.c
Last active December 20, 2015 15:19
implementation for chapter 2 exercises of CSAPP
/*
2.58
just test byte order
*/
int is_big_endian()
{
unsigned short b = 0x1234;
byte* pb = (byte*)&b;
if (*pb == 0x12)