自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 收藏
  • 关注

原创 golang builder,buffer,+的对比

使用buffer或是builder来拼接字符串,会比使用+或+=快func BenchmarkBuffer(b *testing.B) { text := "text" buffer := bytes.Buffer{} b.ResetTimer() for i := 0; i < b.N; i++ { buffer.WriteString(text) }}func BenchmarkBuilder(b *testing.B) { text := "text" builder

2021-11-24 18:51:59 459

原创 golang srpint和itoa对比

数字转换成字符串,使用 strconv.Itoa() 比 fmt.Sprintf() 要快func BenchmarkItoa(b *testing.B) { number := 1234567890 b.ResetTimer() for i := 0; i < b.N; i++ { strconv.Itoa(number) }}func BenchmarkSprint(b *testing.B) { number := 1234567890 b.ResetTimer()

2021-10-19 15:23:18 270

转载 golang defer总结

A "defer" statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function executed areturn statement, reached the end of itsfunction body, or because the corresponding goro...

2020-05-27 18:13:34 132

原创 golang 构造函数

package mainimport ( "fmt")type test struct { a int b string}func newTest1(a int, b string) *test { t := new(test) t.a = a t.b = b return t}func newTest2(a int, b string) *test { return &test{a, b}}type testConstruct func(*test).

2020-05-14 15:48:28 909

原创 redis5.0.7zskiplist

typedef struct zskiplistNode { sds ele; double score; struct zskiplistNode *backward; struct zskiplistLevel { struct zskiplistNode *forward; unsigned long span; } ...

2020-04-17 16:30:04 107

原创 redis4.0.11ziplist

 ziplist通常的内存布局一般是&lt;uint32_t zlbytes&gt; &lt;uint32_t zltail&gt; &lt;uint16_t zllen&gt; &lt;entry&gt; &lt;entry&gt; ... &lt;entry&gt; &lt;uint8_t zlend&gt;,zlbytes表示ziplist占用了多少内存,zltail表示尾结点的偏移量,zl

2019-02-01 02:13:29 111

原创 redis4.0.11整数集

typedef struct intset { uint32_t encoding; uint32_t length; int8_t contents[];} intset;结构体中定义了编码大小、数据长度以及数据内容。引用自https://redissrc.readthedocs.io/en/latest/compress-datastruct/intse...

2019-01-05 01:17:53 114

原创 redis4.0.11字典

typedef struct dictEntry { void *key; union { void *val; uint64_t u64; int64_t s64; double d; } v; struct dictEntry *next;} dictEntry;typedef struct...

2018-12-28 17:24:28 135

原创 redis4.0.11双向链表

typedef struct listNode { struct listNode *prev; struct listNode *next; void *value;} listNode;typedef struct listIter { listNode *next; int direction;} listIter;typedef str...

2018-12-18 16:51:21 228

原创 redis4.0.11字符串

typedef char *sds;虽然它是char指针类型,但是它可以存储非打印字符。sdshdr一共有5个结构体,其中sdshdr5因为可以存储的内容太少不利于扩展,基本上是不用的。一开始看代码的时候就想到一个问题,为什么要有5个结构体,一个结构体不就够用了么?通篇看完所有代码以后发现,划分5个结构体的好处是可以用最适合的内存结构存储字符串,不至于浪费。struct __attri...

2018-12-17 21:20:34 126

原创 memcpy,memmove,bcopy三个函数的内存重叠

bcopy correctly handles overlapping fields, while the behavior of memcpy is undefined if the source and destination overlap. The ANSI C memmove function must be used when the fields overlap.在书里看到这两句...

2018-11-04 22:57:54 349

原创 106 Fermat vs. Pythagoras

https://www.cnblogs.com/scau20110726/archive/2013/01/18/2866957.html用反证法都可以证明上文的结论,m_isUsed这个变量一开始我用的是set,验证后发现set在数据量大的时候效率极低,我以为是因为排序导致的,改用了vector,但是结果是一样的,稍稍比set快了一点,最后还是只能用回数组#include &lt;ios...

2018-09-04 00:11:54 133

原创 105 The Skyline Problem

从最左边遍历到最右边,算出每个点的最高点,把横坐标轴放大了一倍,避免连续点的上下起伏#include &lt;iostream&gt;#include &lt;vector&gt;using namespace std;struct Building{ Building(const int&amp; iLeft, const int&amp; iHeight, const in...

2018-08-30 17:35:24 126

原创 104 Arbitrage

简单问题就是从一个国家到另一个国家能套汇超过1.01即可选用的算法是Floyd-Warshall,稍作修改,状态转移公式是从一个国家i到另一国家j经过次数k能套汇超过1.01#include &lt;iostream&gt;#include &lt;vector&gt;using namespace std;class Arbitrage{public: void rea...

2018-08-30 09:43:22 177

原创 103 Stacking Boxes

动态规划首先把所有的长方体按大小先排好序,从里到外一个个找,设置一个数组vecBoxes用来存储找到的长方体,数组vecBoxes初始值设为最里面的那个长方体,每遍历一次输入的长方体,就遍历一次数组vecBoxes,如果这个长方体包含数组vecBoxes里的一组长方体的最后一个,先把这个组新的长方体存储到vecAddBoxes遍历完数组vecBoxes以后,从vecAddBoxes里找到最...

2018-08-23 14:29:48 177

原创 102 Ecological Bin Packing

没啥内容,穷举就可以了#include &lt;iostream&gt;#include &lt;string&gt;using namespace std;class EcologicalBinPacking{public: void ComputeBottles(const int&amp; iB1b, const int&amp; iB1g, const int&amp...

2018-08-21 10:27:14 226

原创 101 The Blocks Problem

两块砖位置相同时不进行操作#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;string&gt;using namespace std;class Blocks{public: void ReadBlocks(); void ComputeBlocks(); void OutputResult();...

2018-08-20 11:16:56 77

原创 100 The 3n + 1 problem

 这题倒没什么难度,有一个坑就是输入的两个数不一定是顺序的,闲着也是闲着,写点uva练练手吧,争取每天一题吧#include &lt;iostream&gt;using namespace std;class CycleNumber{public: void ComputeCycleNumber(int iStart, int iEnd); void OutputResult...

2018-08-20 01:01:34 96

原创 访问者模式

访问者模式

2016-03-16 10:23:52 193

原创 解释器模式

解释器模式

2016-03-16 00:24:21 206

原创 享元模式

享元模式

2016-03-14 11:40:16 199

原创 中介者模式

中介者模式

2016-03-14 01:50:43 220

原创 职责链模式

职责链模式

2016-03-13 23:00:23 197

原创 命令模式

命令模式

2016-03-13 20:44:10 183

原创 桥接模式

桥接模式

2016-03-13 20:10:52 238

原创 单例模式

单例模式

2016-03-12 19:55:08 275

原创 组合模式

组合模式

2016-03-11 01:31:42 170

原创 备忘录模式

备忘录模式

2016-03-10 02:24:28 223

原创 适配器模式

适配器模式

2016-03-10 01:38:23 212

原创 状态模式

状态模式

2016-03-09 21:13:01 194

原创 观察者模式

观察者模式

2016-03-06 03:48:41 182

原创 建造者模式

建造者模式

2016-02-26 10:55:32 188

原创 工厂模式

工厂模式

2016-02-21 22:26:52 154

原创 代理模式

代理模式

2016-02-21 14:09:42 184

原创 装饰模式

装饰模式

2016-02-20 19:26:26 183

原创 策略模式

策略模式

2016-02-15 16:03:16 189

原创 简单工厂

简单工厂模式

2016-02-14 18:11:40 214

原创 常用容器的erase函数

测试环境是vs2013和gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1vectorc++98iterator erase (const_iterator position);iterator erase (const_iterator first, const_iterator last);c++11  iterator era...

2015-09-14 14:57:21 1096

原创 linux手动安装screen

linux手动安装screen

2015-09-01 00:23:51 1374

原创 linux手动安装apache服务器

网上很多人都写过类似的文章,之前安装过一次,这次第二次安装还是总结一下依赖1:apr下载地址:http://apr.apache.org/download.cgi解压缩:tar -jxvf apr-1.5.2.tar.bz2./configure --prefix=/usr/share/aprmakemake install安装完成以后就可以在/usr/share目录下

2015-06-14 03:13:55 318

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除