Archive for July, 2010
Refine bugzilla extension code
July 17, 2010
Leave a comment
最近一周很恶心的bug
July 9, 2010
Leave a comment
1. 有段时间没写过Java, 以前写一般是边写边学,没有google就没法写的那种。
遇到的问题是,HashMap的key 是一个自定义对象MyObject,要实现我需要的查找得自己重写equals(), hashCode()函数,这些我都知道的,但是还是出问题了,在重写equals()时,比较两个字符串用了 “==”, 应该用String的 equals()判断, 导致HashMap中没法找到。
那么“==”和“equals()”区别是什么呢?
String s1 = new String("str"); String s2 = new String("str");
如果用==号比较,会返回false,因为创建了两个对象,他们在内存中地址的位置是不一样的。
equals, 会返回true,它是java.lang.Object类中的一个方法。因为java中所有的类都默认继承于Object,所以所有的类都有这个方法。
2. HadoopUtils::toInt(const string & str); 总抛异常。试着修复了n边, 跑一次要一个小时的!!!faint!
总之,程序是要精确的, code review 很重要
动态二维数组实现 C
July 1, 2010
Leave a comment
“定义一个二维指针的空间分配和释放 int **ptr”
1. 调用malloc 函数 次数: ( rows + 1)
int** New2DPointer(int m, int n) { if (m > 0 && n > 0) { typedef int * INT_POINTER; int **ptr = NULL; try { ptr = new INT_POINTER[m]; for (int i = 0; i != m; ++i) { ptr[i] = new int[n]; } } catch (bad_alloc e) { std::cout << “Error allocating memory.” << std::endl; } return ptr; } else { std::cout << “invalided input parameters\n”; } } void Delete2DPointer(int **p, int m) { for (int i = 0; i != m; ++i) { delete [] (p[m]); } }
调用malloc 函数 次数: ( 1 + 1)
int **array2d_new(size_t rows, size_t cols) { int **array2d, **end, **cur; int *array; cur = array2d = malloc(rows * sizeof(int *)); if (!array2d) return NULL; array = malloc(rows * cols * sizeof(int)); if (!array) { free(array2d); return NULL; } end = array2d + rows; while (cur != end) { *cur = array; array += cols; cur++; } //print_2d_array(m, rows, cols); return array2d; }
调用malloc 函数次数: ( 1 + 1), 看上去更牛B些
void ** array2d(size_t rows, size_t cols, size_t value_size) { size_t index_size = sizeof(void *) * rows; size_t store_size = value_size * rows * cols; char * a = (char*)malloc(index_size + store_size); if(!a) return NULL; memset(a + index_size, 0, store_size); for(size_t i = 0; i < rows; ++i) ((void **)a)[i] = a + index_size + i * cols * value_size; return (void **)a; } int printf(const char *, ...); int main() { int ** a = (int **)array2d(5, 5, sizeof(int)); assert(a); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) a[i][j] = i*j; //a[4][3] = 42; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) printf("%i\t", a[i][j]); printf("\n"); } free(a); return 0; }
Categories: algorithm & DS
C, DS
Summary[4]
July 1, 2010
Leave a comment
Brief summary these two week’s GSoC. Just having released the first BugStat version 1.0, I am considering adding new features and enhancing existing features. These need to be implemented in these weeks.
- Add more statistic information about users in Bugzilla, perhaps including CC List\ QA Field\Bug patches\ Bug Reviewers, these items have not been verified .
- All these statistic information may be grouped by Products in Bugzilla, and then display
- UI part needs to be improved.