- 博客(103)
- 资源 (1)
- 收藏
- 关注
原创 自己动手写php扩展-类和接口
1.利用php-src提供的工具生成扩展的骨架sudo ./ext_skel.php --ext testclass2.添加类和接口的声明php_testclass.h中PHP_METHOD(TestClass, __construct);PHP_METHOD(TestClass, hello);3.php_testclass.c中static const zend...
2021-03-30 20:41:13
175
原创 87. 扰乱字符串
class Solution { public: bool isScramble(string s1, string s2) { if(s1.length()!=s2.length()) return false; //只要寻找到左边字符集合完整包含右边字符集合,就符合 map<char,int> s1Index,s2Index; int uniq1Numbers=0,uniq2Numbers = .
2020-06-14 23:47:35
246
原创 68. 文本左右对齐
class Solution { public: vector<string> fullJustify(vector<string>& words, int maxWidth) { int lastWordsIndex=-1,//上轮循环处理的最后一个word wordsTotalNow = 0,//当前循环统计的words数量 charsTotalNow=0,//当前循环统计的char数量 c.
2020-06-12 14:40:12
333
原创 42. 接雨水
public: int trap(vector<int>& height) { //1.重点抓住v形,顶点的投影,以及最高点左右分别不同方式计算 //每次遇到新顶点,更新投影,把小于当前投影的数据擦掉,增加当前顶点的投影; //如果当前顶点大于之前所有的投影,则计算数据(最高和第二高决定雨水量),并且擦掉低于该顶点的投影 //2.分治;找到最高点,并以此划分左右两部分,分别计算左右两部分; //左.
2020-06-10 15:17:17
180
原创 41. 缺失的第一个正数
public: int firstMissingPositive(vector<int>& nums) { //有个规律需要思考出来:这个最小数字,肯定处于1~n+1之间 //0-n-1 存储 1-n 之间的数字。 //最后来一次遍历,如果存在缺失,则缺失的即为所求;否则,n+1即为所求 //存储的过程,可以描述为:下标从0-n-1遍历数组,如果符合nums[i-1]==i,则继续, //否则,sw.
2020-06-10 15:16:20
117
原创 37. 解数独
public: void solveSudoku(vector<vector<char> >& board) { if(board.size()<=0 && board[0].size()<=0){ return; } int rowLimits[board.size()][9]; int colLimits[board[0].size()...
2020-06-10 15:11:00
154
原创 22. 括号生成
public: //重点:leftNum >= rightNum 限制条件 vector<string> generateParenthesis(int n) { vector<string> rets; string parenthesis = ""; //2*n个字符;简单的二分即可。 generateParenthesis(n,0,0,parenthesis,rets); r.
2020-06-10 15:05:55
160
原创 10. 正则表达式匹配
public: bool isMatch(string s, string p) { int sLength=s.length(),pLength = p.length(),i=0,j=0;//i,s的逆序号,j,p的逆序号 bool dp[sLength+1][pLength+1];//s尾部和p尾部字符串的匹配数组,0-slength,0-plength for (int i = 0; i <= sLength; ...
2020-06-10 14:56:11
192
转载 转:nginx源码学习资源(不断更新)
nginx源码学习是一个痛苦又快乐的过程,下面列出了一些nginx的学习资源。 首先要做的当然是下载一份nginx源码,可以从nginx官方网站下载一份最新的。看了nginx源码,发现这是一份完全没有注释,完全没有配置文档的代码。 现在你最希望要的是一份注释版的nginx源码,可以从下面的链接中下载一份:https://github.com/jianfengye/nginx...
2019-02-15 18:28:21
142
原创 php-fpm源码浅析
php-src/sapi/fpm/fpm/fpm.c关于fpm初始化关键代码 0 > fpm_php_init_main() || 0 > fpm_stdio_init_main() || 0 > fpm_conf_init_main(test_conf, force_daemon) || 0 &g...
2019-02-13 10:39:27
538
原创 resty中redis返回空
resty中对于redis查询不存在的键,返回的空是USERDATA类型,需额外处理,转为boolean是true;
2019-01-23 15:42:07
465
原创 php中ZTS
1.ZTS zend thread safety,php线程安全,适用于Apache2+worker MPM2.ts_allocate_id:allocates a new thread-safe-resource id;函数 TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_cto...
2018-12-16 17:39:15
3002
原创 fastcgi协议管窥
纪录的通用结构:typedef struct { unsigned char version; unsigned char type; unsigned char requestIdB1; unsigned char requestIdB0; unsigned char c...
2018-12-09 22:25:00
182
转载 技术-转发
http://blog.youkuaiyun.com/xiaofei_hah0000/article/details/8984192 服务器的想法http://blog.youkuaiyun.com/laoyi19861011/article/category/831215 libevent手册http://blog.youkuaiyun.com/v_july_v/article/details/6284050 算法...
2018-11-29 19:38:12
184
原创 gdb 调试 php-cp扩展 redisProxy与pool_server的长连接
1.安装gdb sudo apt-get install gdb2.进入php-cp扩展目录(已经编译过了),源码https://github.com/swoole/php-cp获取要调试函数的真实函数名 zim_redis_connect_pool_select$ nm connect_pool.so....0000000000012170 t zim_re...
2018-10-24 19:13:55
645
转载 转:linux常用的监控命令
1. top显示所有正在运行而且处于活动状态的实时进程, 而且会定期更新显示结果;它显示了CPU使用率,内存使用率,交换内存使用大小,调整缓存使用大小,缓冲区使用大小,进程PID, 使用的命令等信息。 2. vmstat一般是通过两个数字参数来完成的,第一个参数是采样时间间隔,单位是秒, 第二个参数是采样的次数r: 表示运行队列,如果队列过大说明CPU很繁忙,一般...
2018-10-10 12:11:00
181
原创 centos7忘记密码
1.进入grub修改,启动后按e2.mount -o remount,rw /3.依次输入以下命令进行root密码修改chroot /sysroot/再输入touch / .autorelabel (touch、/、.autorelabel有空格)最后 passwd root 依次键入你的密码 4.重启,选择用户名,输入密码 ...
2018-09-29 14:33:58
226
原创 php源码之DateTime类
1.声明在php_date.h/* Advanced Interface */PHP_METHOD(DateTime, __construct);PHP_METHOD(DateTime, __wakeup);PHP_METHOD(DateTime, __set_state);PHP_METHOD(DateTime, createFromImmutable);/*其他方法,以映射的方...
2018-09-21 18:44:32
434
原创 自己动手写php扩展
1.下载最新版php源码git clone https://github.com/php/php-src2.切换到ext目录cd php-srccd ext 3.利用php-src提供的工具生成扩展的骨架./ext_skel.php --ext test便可以在当前目录查看到test文件夹--扩展的文件夹./ext_skel.php具体怎么使用,可在当前目录输...
2018-09-20 23:33:49
554
原创 PHP源码之date函数
date函数的实现在源码目录的 ext/date。1.定义函数的参数表:ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1) ZEND_ARG_INFO(0, format) ZEND_ARG_INFO(0, timestamp)ZEND_END_ARG_INFO()将其展开,得到#define ZEND_ARG_INFO(pass_...
2018-09-13 19:15:34
581
原创 php内核寻找ini的优先过程
php_init_config函数的作用是读取php.ini文件,设置配置参数,加载zend扩展并注册PHP扩展函数。此函数分为如下几步: 初始化参数配置表,调用当前模式下的ini初始化配置,比如CLI模式下,会做如下初始化:INI_DEFAULT("report_zend_debug", "0");INI_DEFAULT("display_errors", "1");不过在其它模式下...
2018-08-23 16:32:37
361
原创 redis源码中的ziplist zskiplist 压缩表和跳表
在压缩双链表中,节省了前驱和后驱指针的空间,在 64 位机器上共节省了 8 个字节, 这让数据在内存中更为紧 凑。只要清晰的描述每个数据项的边界,就可以轻易得到前驱后 驱数据项的位置,ziplist 就是这么做的。 ziplist 的格式可以表示为:<zlbytes><zltail><zllen><entry>...<entry>&l...
2018-08-23 16:32:26
2453
原创 php 内核hashtable中 pListNext和pNext的区别
pListNext指示在php数组中加入的先后顺序pNext指在存储的同一个bucket(链表法解决冲突)中的链表先后位置,注意是头插法,所以越后加入的元素在同一bucket中的位置越靠前;...
2018-08-23 16:20:03
715
原创 redis pipeline 和 multi
redis的pipeline是批量操作,以提高性能为主,无法保证原子性;multi watch exec discard unwatch 主要针对原子性,性能会有所下降
2018-08-07 11:12:01
675
原创 leetcode125. Valid Palindrome
class Solution {public: bool isPalindrome(string s) { int head = 0; int tail = s.size() - 1; if(tail<0) return true; while(head<=tail){ if(!((s[head]>...
2018-03-14 19:11:37
146
原创 123. Best Time to Buy and Sell Stock III
class Solution {public: int maxProfit(vector<int>& prices) { vector<vector<int>> maxProfits(prices.size(),vector<int>(2,0)); int maxPos = prices.si...
2018-03-14 18:49:00
133
原创 122. Best Time to Buy and Sell Stock II
class Solution {public: int maxProfit(vector<int>& prices) { int maxPos = prices.size() - 1; if(maxPos < 0 ) return 0; int maxTemp = 0 ;//短线的上升沿最大值...
2018-03-14 16:30:47
142
原创 121. Best Time to Buy and Sell Stock
class Solution {public: int maxProfit(vector<int>& prices) { vector<vector<int>> maxProfits(prices.size(),vector<int>(2,0)); int maxPos = prices.size() - 1...
2018-03-14 15:18:13
147
原创 leetcode120. Triangle
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { if(triangle.size()<=0) return 0; int k = triangle.size() - 1; vector<int> res...
2018-03-13 16:35:54
195
原创 leetcode119. Pascal's Triangle II
class Solution {public: vector<int> getRow(int rowIndex) { vector<int> result(rowIndex+1); int cursor = 1; result[0] = 1; int smallCursor = 1; ...
2018-03-13 15:41:36
180
原创 leetcode118. Pascal's Triangle
class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> result; if(numRows<=0) return result; result.push_bac...
2018-03-13 14:03:58
146
原创 117. Populating Next Right Pointers in Each Node II
class Solution {public: void connect(TreeLinkNode *root) { if(root==NULL) return ; TreeLinkNode *start = root; TreeLinkNode *rootcur = start; TreeLinkNode *tail=NULL; ...
2018-03-13 12:07:32
117
原创 116. Populating Next Right Pointers in Each Node
class Solution {public: void connect(TreeLinkNode *root) { if(root==NULL) return ; TreeLinkNode *start = root; TreeLinkNode *cur = start; while(start){ cur =...
2018-03-13 12:06:41
141
原创 leetcode115. Distinct Subsequences
class Solution {public: int numDistinct(string s, string t) { if(t.size()<=0) return 1; if((s.size()<=0 && t.size()>0) || s.size()<t.size()){ return 0; ...
2018-03-08 19:32:09
180
原创 114. Flatten Binary Tree to Linked List
class Solution {public: void flatten(TreeNode* root) { if(root==NULL) return ; flattenTree(root); } TreeNode* flattenTree(TreeNode* root) { if(root==NULL) return NULL; ...
2018-03-07 15:39:30
152
原创 113. Path Sum II
class Solution {public: vector<vector<int>> pathSum(TreeNode* root, int sum) { vector<vector<int>> result; vector<int> temp; pathSum(root,sum,temp...
2018-03-07 14:56:10
113
原创 112. Path Sum
class Solution {public: bool hasPathSum(TreeNode* root, int sum) { if(root==NULL) return false; if(root->left==NULL && root->right==NULL){ if(sum == ...
2018-03-07 14:30:39
143
原创 111. Minimum Depth of Binary Tree
class Solution {public: int minDepth(TreeNode* root) { if(root==NULL) return 0; if(root->left==NULL && root->right==NULL){ return 1; } if(root-&...
2018-03-07 14:17:57
123
原创 110. Balanced Binary Tree
class Solution {public: bool isBalanced(TreeNode* root) { if(root==NULL) return true; int left = treeDiffer(root->left);cout<<left<<endl; int right = treeDiffer(...
2018-03-06 19:25:33
129
原创 109. Convert Sorted List to Binary Search Tree
class Solution {public: TreeNode* sortedListToBST(ListNode* head) { ListNode* tail = head; ListNode* middle = head; while(tail!=NULL&&tail->next!=NULL){ t...
2018-03-06 18:42:28
137
Artificial Intelligence - A Modern Approach 3
2017-10-25
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人