ijktree:
//tree的构建,tp是根节点,next是要插入的节点,
void *ijk_av_tree_insert(IjkAVTreeNode**tp, void *key,
int (*cmp)(const void *key, const void *b),IjkAVTreeNode**next){
IjkAVTreeNode *t = *tp;
if (t) { //如果有根节点
}else{ //如果没有根节点
*tp = *next; //将next作为根节点
}
}
ijkstl:map相关的操作
typedef map<int64_t, void *> IjkMap; //map是模版类,使用typedef给map起了个别名IjkMap
void* ijk_map_create() {
IjkMap*data =new IjkMap(); //创建一个IjkMap对象
return data;
}
void ijk_map_put(void *data,int64_t key, void *value) { //存取key,value数据
IjkMap*map_data =reinterpret_cast(data); //reinterpret_cast为强制类型转换
if (!map_data)
return;
(*map_data)[key] = value; //key,value存储
}
void* ijk_map_get(void *data,int64_t key) { //根据key得到value
IjkMap*map_data =reinterpret_cast(data);
if (!map_data)
return NULL;
IjkMap::iteratorit = map_data->find(key); //根据key寻找
if (it != map_data->end()) { //如果找到就返回 it->second否则返回NULL
return it->second;
}
return NULL;
}
void* ijk_map_index_get(void *data, int index) { //根据index得到value
IjkMap*map_data =reinterpret_cast(data);
if (!map_data || map_data->empty())
return NULL;
IjkMap::iteratorit;
it = map_data->begin();
for (int i =0; i < index; i++) {
it = it++;
if (it == map_data->end()) {
return NULL;
}
}
return it->second;
}
网友评论