This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export HADOOP_HOME=$HOME/Applications/hadoop | |
main() { | |
if [ "$1" == "rebuild" ]; then | |
myhadoop_build | |
myhadoop_config | |
rm -f $HADOOP_HOME/logs/*.* # Delete old logs | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TreeNode *LCA(TreeNode *root, TreeNode *p, TreeNode *q) { | |
if (root == nulltpr || root == p || root == q) | |
return root; | |
else { | |
TreeNode *L = LCA(root->left, p, q); | |
TreeNode *R = LCA(root->right, p, q); | |
if (L && R) | |
return root; | |
else | |
return L ? L : R; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const unsigned char BitReverseTable256[256] = | |
{ | |
# define R2(n) n, n + 2*64, n + 1*64, n + 3*64 | |
# define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16) | |
# define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 ) | |
R6(0), R6(2), R6(1), R6(3) | |
}; | |
// reverse 32-bit value, 8 bits at time | |
unsigned int reverse_int(unsigned int v) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int gcd(int a, int b) { | |
return b == 0 ? a : gcd(b, a % b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool ends_with(const std::string &str, const std::string &ending) { | |
if (str.length() < ending.length()) | |
return false; | |
return str.compare(str.length() - ending.length(), ending.length(), ending) == 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int parseline(char *buf, char **argv) { | |
char *delim; | |
int argc = 0; | |
buf[strlen(buf) - 1] = ' '; | |
while (*buf && (*buf == ' ')) | |
buf++; | |
while ((delim = strchr(buf, ' '))) { | |
argv[argc++] = buf; | |
*delim = '\0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <vector> | |
#include <set> | |
template <typename Type> | |
void remove_duplicate(std::vector<Type>& vec) { | |
std::sort(vec.begin(), vec.end()); | |
vec.erase(unique(vec.begin(), vec.end()), vec.end()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<string> split(const string &str, const char delim = ' ') { | |
stringstream ss(str); | |
vector<string> strvec; | |
string tmp; | |
while (std::getline(str, tmp, delim)) | |
strvec.push_back(tmp); | |
return strvec; // std::move() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline bool starts_with(const string &big_str, const string &small_str) { | |
return big_str.compare(0, small_str.length(), small_str) == 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t replace_all(string &str, const string &from, const string &to) { | |
size_t count = 0; | |
size_t pos = 0; | |
while ((pos = str.find(from, pos)) != string:npos) { | |
str.replace(pos, from.length(), to); | |
pos += to.length(); | |
++count; | |
} | |