- 博客(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
523
原创 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
368
转载 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
191
原创 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
958
原创 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
136
原创 redis4.0.11ziplist
ziplist通常的内存布局一般是<uint32_t zlbytes> <uint32_t zltail> <uint16_t zllen> <entry> <entry> ... <entry> <uint8_t zlend>,zlbytes表示ziplist占用了多少内存,zltail表示尾结点的偏移量,zl
2019-02-01 02:13:29
140
原创 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
148
原创 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
167
原创 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
268
原创 redis4.0.11字符串
typedef char *sds;虽然它是char指针类型,但是它可以存储非打印字符。sdshdr一共有5个结构体,其中sdshdr5因为可以存储的内容太少不利于扩展,基本上是不用的。一开始看代码的时候就想到一个问题,为什么要有5个结构体,一个结构体不就够用了么?通篇看完所有代码以后发现,划分5个结构体的好处是可以用最适合的内存结构存储字符串,不至于浪费。struct __attri...
2018-12-17 21:20:34
149
原创 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
401
原创 106 Fermat vs. Pythagoras
https://www.cnblogs.com/scau20110726/archive/2013/01/18/2866957.html用反证法都可以证明上文的结论,m_isUsed这个变量一开始我用的是set,验证后发现set在数据量大的时候效率极低,我以为是因为排序导致的,改用了vector,但是结果是一样的,稍稍比set快了一点,最后还是只能用回数组#include <ios...
2018-09-04 00:11:54
166
原创 105 The Skyline Problem
从最左边遍历到最右边,算出每个点的最高点,把横坐标轴放大了一倍,避免连续点的上下起伏#include <iostream>#include <vector>using namespace std;struct Building{ Building(const int& iLeft, const int& iHeight, const in...
2018-08-30 17:35:24
152
原创 104 Arbitrage
简单问题就是从一个国家到另一个国家能套汇超过1.01即可选用的算法是Floyd-Warshall,稍作修改,状态转移公式是从一个国家i到另一国家j经过次数k能套汇超过1.01#include <iostream>#include <vector>using namespace std;class Arbitrage{public: void rea...
2018-08-30 09:43:22
214
原创 103 Stacking Boxes
动态规划首先把所有的长方体按大小先排好序,从里到外一个个找,设置一个数组vecBoxes用来存储找到的长方体,数组vecBoxes初始值设为最里面的那个长方体,每遍历一次输入的长方体,就遍历一次数组vecBoxes,如果这个长方体包含数组vecBoxes里的一组长方体的最后一个,先把这个组新的长方体存储到vecAddBoxes遍历完数组vecBoxes以后,从vecAddBoxes里找到最...
2018-08-23 14:29:48
206
原创 102 Ecological Bin Packing
没啥内容,穷举就可以了#include <iostream>#include <string>using namespace std;class EcologicalBinPacking{public: void ComputeBottles(const int& iB1b, const int& iB1g, const int&...
2018-08-21 10:27:14
252
原创 101 The Blocks Problem
两块砖位置相同时不进行操作#include <iostream>#include <vector>#include <string>using namespace std;class Blocks{public: void ReadBlocks(); void ComputeBlocks(); void OutputResult();...
2018-08-20 11:16:56
104
原创 100 The 3n + 1 problem
这题倒没什么难度,有一个坑就是输入的两个数不一定是顺序的,闲着也是闲着,写点uva练练手吧,争取每天一题吧#include <iostream>using namespace std;class CycleNumber{public: void ComputeCycleNumber(int iStart, int iEnd); void OutputResult...
2018-08-20 01:01:34
123
原创 常用容器的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
1136
原创 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
358
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人