现在可以到github上下载目前为止的所有文件了。
其中,hjstl_vector目前无法正常工作,后期会回来修复bug。
下面是地址:https://github.com/pandening/HJSTL

#ifndef _HJ_STL_HEAP_
#define _HJ_STL_HEAP_
/*
* Author:hujian
* Time:2016/5/4
* discription:this file is about heap.
*
* NOTICE:you should not use hjstl_vector in anywhere.
* because the hjstl_vector has too much bugs.
* it not work till now.
*
*/#include "hjstl_iterator.h"template<class RandomAccessIterator,class Distance,class Type>
void __hjstl_push_heap(RandomAccessIterator first, Distance holeIndex,Distance topIndex, Type value){//find the parent of the holeindex.Distance parent = (holeIndex - 1) / 2;while (parent > topIndex&&*(first + parent) < value){*(first + holeIndex) = *(first + parent);holeIndex = parent;parent = (holeIndex - 1) / 2;}*(first + holeIndex) = value;
}template<class RandomAccessIterator,class Distance,class Type>
void __hjstl_push_heap_aux(RandomAccessIterator first, RandomAccessIterator last, Distance*, Type*){__hjstl_push_heap(first, hjstl_distance((last - first) - 1), hjstl_distance(0), Type(*(last - 1)));
}template<class RandomAccessIterator>
inline void hjstl_push_heap(RandomAccessIterator first, RandomAccessIterator last)
{__hjstl_push_heap_aux(first, last, hjstl_distance_type(first), hjstl_value_type(first));
}template<class RandomAccessIterator,class Distance,class Type,class Compare>
void __hjstl_push_heap(RandomAccessIterator first, Distance holeIndex,Distance topIndex, Type value, Compare comp){//find the parentDistance parent = (holeIndex - 1) / 2;while (holeIndex > topIndex&&comp(*(first + parent), value)){*(first + holeIndex) = *(first + parent);holeIndex = parent;parent = (holeIndex - 1) / 2;}*(first + holeIndex) = value;
}template<class RandomAccessIterator,class Compare,class Distance,class Type>
void __hjstl_push_heap_aux(RandomAccessIterator first, RandomAccessIterator last,Compare comp, Distance*, Type*){__hjstl_push_heap(first, hjstl_distance((last - first) - 1), hjstl_distance(0), Type(*(last - 1)), comp);
}template<class RandomAccessIterator,class Compare>
void hjstl_push_heap(RandomAccessIterator first, RandomAccessIterator last,Compare comp){__hjstl_push_heap_aux(first, last, comp, hjstl_distance_type(first), hjstl_value_type(first));
}//adjust the heap
template<class RandomAccessIterator,class Distance,class Type>
void __hjstl_adjust_heap(RandomAccessIterator first, Distance holeIndex, Distance len, Type value)
{Distance topIndex = holeIndex;//the right child of the holeIndexDistance secondChild = 2 * (holeIndex + 1);while (secondChild < len){//the secondChild is the max value(leftchild,rightchild)if (*(first + secondChild) < *(first + (secondChild - 1))){secondChild--;}*(first + holeIndex) = *(first + secondChild);holeIndex = secondChild;secondChild = 2 * (secondChild + 1);}//if no right child.just let the holeindex=>the left child.if (secondChild == len){*(first + holeIndex) = *(first + (secondChild - 1));holeIndex = secondChild - 1;}//push heap again__hjstl_push_heap(first, holeIndex, topIndex, value);
}template<class RandomAccessIterator,class Distance,class Type,class Compare>
void __hjstl_adjust_heap(RandomAccessIterator first, Distance holeIndex,Distance len, Type value, Compare comp)
{Distance topIndex = holeIndex;Distance secondChild = 2 * (holeIndex + 1);while (secondChild < len){if (comp(*(first + secondChild), *(first + (secondChild - 1))))secondChild--;*(first + holeIndex) = *(first + secondChild);holeIndex = secondChild;//the secondChild is the right child.secondChild = 2 * (secondChild + 1);}if (secondChild == len){*(first + holeIndex) = *(first + (secondChild - 1));holeIndex = secondChild - 1;}//adjust again__hjstl_push_heap(first, holeIndex, topIndex, value, comp);
}template<class RandomAccessIterator,class Type,class Distance>
void __hjstl_pop_heap(RandomAccessIterator first, RandomAccessIterator last,RandomAccessIterator result, Type value, Distance*)
{/*the last value is the result*/*result = *first;__hjstl_adjust_heap(first, Distance(0), Distance(last - first), value);
}template<class RandomAccessIterator,class Type>
void __hjstl_pop_heap_aux(RandomAccessIterator first, RandomAccessIterator last,Type*){__hjstl_pop_heap(first, last - 1, last - 1, Type(*(last - 1)), hjstl_distance_type(first));
}
template<class RandomAccessIterator>
void hjstl_pop_heap(RandomAccessIterator first, RandomAccessIterator last)
{__hjstl_pop_heap_aux(first, last, hjstl_value_type(first));
}///-------------
template<class RandomAccessIterator, class Type, class Distance,class Compare>
void __hjstl_pop_heap(RandomAccessIterator first, RandomAccessIterator last,RandomAccessIterator result, Type value,Compare comp,Distance*)
{/*the last value is the result*/*result = *first;__hjstl_adjust_heap(first, Distance(0), Distance(last - first), value,comp);
}template<class RandomAccessIterator, class Type,class Compare>
void __hjstl_pop_heap_aux(RandomAccessIterator first, RandomAccessIterator last,Type*,Compare comp){__hjstl_pop_heap(first, last - 1, last - 1, Type(*(last - 1)), comp,hjstl_distance_type(first));
}
template<class RandomAccessIterator,class Compare>
void hjstl_pop_heap(RandomAccessIterator first, RandomAccessIterator last,Compare comp)
{__hjstl_pop_heap_aux(first, last, hjstl_value_type(first),comp);
}///--make heap
template<class RandomAccessIterator,class Type,class Distance>
void __hjstl_make_heap(RandomAccessIterator first, RandomAccessIterator last,Type*, Distance*)
{if (last - first < 2) return;//0 1Distance len = last - first;//this is the first child-tree we need to make-heap's rootDistance parent = (len - 2) / 2;while (1){__hjstl_adjust_heap(first, parent, len, Type(*(first + parent)));if (parent == 0) return;/*end.*/parent--;}
}template<class RandomAccessIterator>
void hjstl_make_heap(RandomAccessIterator first, RandomAccessIterator last)
{__hjstl_make_heap(first, last, hjstl_value_type(first), hjstl_distance_type(first));
}/--
template<class RandomAccessIterator, class Type, class Distance,class Compare>
void __hjstl_make_heap(RandomAccessIterator first, RandomAccessIterator last,Compare comp,Type*, Distance*)
{if (last - first < 2) return;//0 1Distance len = last - first;//this is the first child-tree we need to make-heap's rootDistance parent = (len - 2) / 2;while (1){__hjstl_adjust_heap(first, parent, len, Type(*(first + parent)),comp);if (parent == 0) return;/*end.*/parent--;}
}template<class RandomAccessIterator,class Compare>
void hjstl_make_heap(RandomAccessIterator first, RandomAccessIterator last,Compare comp)
{__hjstl_make_heap(first, last,comp,hjstl_value_type(first), hjstl_distance_type(first));
}//sort
template<class RandomAccessIterator,class Compare>
void hjstl_sort_heap(RandomAccessIterator first, RandomAccessIterator last,Compare comp)
{while (last - first > 1){hjstl_pop_heap(first, last--,comp);}
}template<class RandomAccessIterator>
void hjstl_srot_heap(RandomAccessIterator first, RandomAccessIterator last)
{while (last - first > 1){hjstl_pop_heap(first, last--);}
}
#endif  /*end of hjst heap*/
///<2016/5/4 hujian /nankai.>

STL源码剖析heap相关推荐

  1. STL 源码剖析 heap堆

    heap不属于STL容器的组件,属于幕后角色,是priority_queue的助手 priority_queue 允许用户以任何次序将任何元素推入容器内,但是取出的时候需要从优先级最高(也就是数值最高 ...

  2. STL源码剖析 heap堆结构

    heap一般特指max-heap,即最大的元素位于heap和array的首部 heap不提供遍历功能,也不提供迭代功能

  3. STL源码剖析学习二:空间配置器(allocator)

    STL源码剖析学习二:空间配置器(allocator) 标准接口: vlaue_type pointer const_pointer reference const_reference size_ty ...

  4. STL源码剖析 空间配置器 查漏补缺

    ptrdiff_t含义 减去两个指针的结果的带符号整数类型 ptrdiff_t (Type support) - C 中文开发手册 - 开发者手册 - 云+社区 - 腾讯云 std::set_new_ ...

  5. C++ STL源码剖析 笔记

    写在前面 记录一下<C++ STL源码剖析>中的要点. 一.STL六大组件 容器(container): 各种数据结构,用于存放数据: class template 类泛型: 如vecto ...

  6. SGI STL源码剖析——空间配置器

    SGI STL源码剖析--空间配置器 前言 空间配置器 SGI空间配置器 内存配置和对象构造 构造和析构 空间的配置和释放 第一级配置器 第二级配置器 空间配置 重新填充 重中之重的内存池 前言    ...

  7. 【《STL源码剖析》提炼总结】 第1节:空间配置器 allocator

    文章目录 一. 什么是空间配置器 二. STL allocator的四个操作: allocate,deallocate,construct,destroy `construct()` `destroy ...

  8. STL源码剖析学习七:stack和queue

    STL源码剖析学习七:stack和queue stack是一种先进后出的数据结构,只有一个出口. 允许新增.删除.获取最顶端的元素,没有任何办法可以存取其他元素,不允许有遍历行为. 缺省情况下用deq ...

  9. 《STL源码剖析》学习-- 1.9-- 可能令你困惑的C++语法1

    最近在看侯捷的<STL源码剖析>,虽然感觉自己c++看得比较深一点,还是感觉还多东西不是那么明白,这里将一些细小的东西或者概念记录一下. 有些东西是根据<C++编程思想>理解的 ...

  10. 《STL源码剖析》学习--6章--_rotate算法分析

     最近在看侯捷的<STL源码剖析>,其中有许多不太明白之处,后经分析或查找资料有了些理解,现记录一下. <STL源码剖析>学习--6章--random access ite ...

最新文章

  1. [2010山东ACM省赛] Greatest Number(数的组合+二分搜索)
  2. Python模块制作
  3. 如何打开python的交互窗口-Python多版本情况下四种快速进入交互式命令行的操作技巧...
  4. 运行Google CTemplate首页的例子遇到_CrtIsValidHeapPointer异常
  5. ACM错误提示/错误原因
  6. 【洛谷 P2051】 [AHOI2009]中国象棋(DP)
  7. MySQL中述职类型的长度问题
  8. 高精度:麦森数*(洛谷P1045)
  9. 工作流性能优化(敢问activiti有扩展性?)(3)
  10. 浙大 PAT b1022
  11. python交互式帮助的进入、使用和退出_python退出交互式???
  12. 缠中说禅形态挖掘之七笔形态
  13. 汇编语言:协处理器浮点指令:FILD
  14. 记录手机连接笔记本热点无法上网问题
  15. p1904 p1903
  16. a113 智能音箱芯片方案_智能音箱九大芯片方案商及其生产厂商和代表作品介绍-控制器/处理器-与非网...
  17. 如何配置数据库带有下划线字段对应Java实体类属性(驼峰命名)
  18. 雨天在火车站台上撑伞会触电吗?
  19. vue发送请求时遇到index.vue?6ced:90 Uncaught (in promise) TypeError: Cannot read properties of undefined
  20. 使用while循环,求1+11+111+1111+11111+111111

热门文章

  1. HDU 6330--Visual Cube(构造,计算)
  2. 【Selenium2】【项目实战】
  3. KbmMW 4.30.00 发布
  4. 自己写好记的Oracle的 Group By 、 Group By Rollup和Group By Cube基础
  5. 身体排毒,自己就可以轻松搞定 - 生活至上,美容至尚!
  6. 免费源码赠送之 printf(C语言简化版)
  7. 什么是南向接口和北向接口?
  8. 散射回波仿真Matlab,基于matlab的体目标回波模拟方法与流程
  9. java如何让cpu过负荷_服务器开发过载问题如何解决
  10. gcc CFLAGS中调试和优化标志