自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 资源 (1)
  • 收藏
  • 关注

原创 kubebuilder+code-generator开发k8s的controller

本文记录用kubebuilder和code-generator开发k8s的crd控制器。

2024-01-12 10:47:32 1288

原创 etcd选举源码分析和例子

本文主要介绍etcd在分布式多节点服务中如何实现选主。

2023-09-08 17:26:47 597

原创 gin的占位符:和通配符*

比如用占位符注册了/royal/:id,可以继续注册/royal/123,并且访问/royal/123会精确匹配注册的路由。在 Gin 路由中,可以使用一个通配符(*)或一个占位符(:)来捕获 URL 的一部分。同一路由中,通配符和占位符可以同时使用,但是占位符要在通配符的前面,否则会panic。查看源码发现,Param会匹配第一个相同的key,也就是第一个id。占位符注册的路由以后,可以注册相同前缀的路由。但如果是通配符,则不可以,会报panic。如果通配符什么都不带,则返回的是一个/。

2023-08-11 17:20:25 1923

原创 go http请求出现“connect:cannot-assign-requested-address“以及TIME-WAIT的问题

所以在高并发场景下,因为每个host的最大连接数没有限制,所以会不停的dail新连接。但是每个host的最大空闲连接数为2,所以只能维持两个空闲连接,其他的连接必须关闭。最近的项目中,在大并发的场景下,go的后台程序出现了connect:cannot-assign-requested-address的问题。要设置每个host的最大连接数,当空闲、活跃和dail的连接数超过这个值,会挂起dail。MaxConnsPerHost:每个host的最大连接数,包括:活跃、空闲和dailing中的。

2023-07-25 11:27:27 1405

原创 一文讲清go的http请求处理过程

这里再总结一下:TCPListener调用自己的方法Accept以后,返回的是一个TCPConn结构体,该结构体继承了conn结构体的方法,实现了interface Conn中的方法。6、从本质上看,在accept建立一条新的tcp连接后,才会继续往下执行,初始化新的http意义下的conn,所以go c.serve实际上处理的是一个tcp连接。这个函数返回的是一个Listener这样的interface,可以看到这里面的一些诸如Accept 的方法和之前unix中的socket编程很一致。

2023-07-21 16:02:46 1147

原创 go的sort包源码分析与排序算法解析

1、sort包的使用​ Sort函数的源码:func Sort(data Interface) { n := data.Len() quickSort(data, 0, n, maxDepth(n))}​ 再看Interface的类型,是一个包含了三个函数的接口类型:type Interface interface { // Len is the number of elements in the collection. Len() int Less(i, j int) bool

2021-11-08 15:48:02 297

原创 二叉树填充每个节点的下一个右侧节点指针

/** * Definition for a Node. * type Node struct { * Val int * Left *Node * Right *Node * Next *Node * } */type CircleQueue struct { Buff [4096]*Node Cap int Length int Start int End int}func (p *CircleQueue)

2021-07-13 10:10:11 90

原创 从前序和中序遍历构建二叉树

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func caller(preorder []int, inorder []int, indexMap map[int]int,inOrderStart, inOrderEnd, preOrderStart, preOrderEnd in

2021-07-08 20:47:11 77

原创 从中序与后序遍历序列构造二叉树递归做法

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func caller(inorder []int, postorder []int, indexMap map[int]int, inOrderStart, inOrderEnd, postOrderStart, postOrderE

2021-07-08 17:08:43 121

原创 leetcode面试题二叉树路径总和迭代实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */type StackNode struct { Parr [1000]*TreeNode Index int}func(s *StackNode) IsEmpty() bool { if s.Index &l

2021-06-01 17:12:42 86

原创 leetcode二叉树路径总和递归实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func hasPathSum(root *TreeNode, targetSum int) bool { if nil == root { return false } if root.Left

2021-06-01 14:45:44 64

原创 leetcode判断是否二叉镜像树迭代实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */type MyCirQueue struct { Parr []*TreeNode Head int Tail int Cap int Size int}func QueueConstruc

2021-06-01 14:25:20 56

原创 判断是不是对称二叉树递归方法

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func isSymmetricNode(left, right *TreeNode) bool { if left == nil && right == nil { return true

2021-05-28 16:19:27 52

原创 leetcode二叉树面试求最大深度

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func Max(a, b int) int { if a >= b { return a }else { return b }}func maxDepth(root *

2021-05-28 15:53:31 42

原创 leetcode面试二叉树的层序遍历

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */type MyCircularQueue struct { Parr []*TreeNode Head int Tail int Length int Cap int}func Constr

2021-05-28 15:30:47 47

原创 循环队列leetcode面试解答

type MyCircularQueue struct { Parr []int Head int Tail int Length int Cap int}func Constructor(k int) MyCircularQueue { return MyCircularQueue{ Parr: make([]int, k), Head: 0, Tail: 0, Length: k,

2021-05-28 09:22:27 61

原创 二叉树后序遍历迭代实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } *//** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right

2021-05-27 14:44:28 145

原创 二叉树后序遍历递归实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func postorderTraversal(root *TreeNode) []int { rsp := make([]int, 0) if nil == root { return rsp }

2021-05-27 09:45:10 79

原创 二叉树中序遍历迭代实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */type Stack struct { Parr [1000]*TreeNode Index int}func(s *Stack) IsEmpty() bool { if s.Index <= 0 {

2021-05-27 09:26:44 53

原创 二叉树中序遍历递归实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func inorderTraversal(root *TreeNode) []int { rsp := make([]int, 0) if nil == root { return rsp }

2021-05-26 17:27:26 137

原创 二叉树前序遍历迭代实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */type Stack struct { Parr [1000]*TreeNode Index int}func(s *Stack) IsEmpty() bool { if s.Index <= 0 {

2021-05-26 16:55:21 79

原创 二叉树前序递归实现

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func preorderTraversal(root *TreeNode) []int { rsp := make([]int, 0) if nil == root { return rsp

2021-05-26 16:28:19 60

原创 golang的interface与反射实现原理

1、什么是interface​ interface通过定义一系列的方法集合指定了其他类型的行为。对于一个类型,当且仅当它实现了某一个interface方法集的所有方法,我们称这个类型满足了这个interface。可以理解为interface是一个抽象的类型,这个类型定义了一系列的方法,当某个其他类型完全实现了该interface的所有的方法,可以称这个类型是当前抽象interface的一个实例。可以把interface理解为一个合约,方法即是合同细节,当其他类型满足了所有细节(方法),即可认为该类型满足了

2021-05-06 16:08:25 1608 3

原创 循环队列的c实现

#include <stdio.h>#include <stdlib.h>#define SUCCESS 0#define FAILED -1typedef struct { int * parr; int head; int tail; int length;} CircleQueue;CircleQueue queue;int init(CircleQueue* p, int length) { p->parr

2021-03-17 15:30:08 104

原创 golang内存分配与管理

概述​ golang的内存分配机制源自Google的tcmalloc算法,英文全称thread caching malloc,从名字可以看出,是在原有基础上,针对多核多线程的内存管理进行优化而提出来的。该算法的核心思想是内存的多级管理,进而降低锁的粒度;将内存按需划成大小不一的块,减少内存的碎片化。为每个P,也就是go协程调度模型了里面的逻辑处理器维护一个mcache结构体的独立内存池,只有当该内存池不足时,才会向全局mcentral和mheap结构体管理的内存池申请。为每一个P维持一个私有的本地内存池,

2021-03-12 16:14:07 1872 3

原创 gin框架源码浅析

最近项目中的几个模块用到了Gin框架,记录一下看源码的心得。 1、Gin框架简介​ Gin框架是一个go开源的轻量级http服务器框架​ 官方文档:https://gin-gonic.com/docs/​ 源码地址:https://github.com/gin-gonic/gin​ 中文教程:https://learnku.com/docs/gin-gonic/2019​ 主要有以下功能特性:​ a、基于redixtree的路由策略,没有使用反射,占用内存小。采用.

2021-03-02 14:44:47 836

原创 基于链表的队列实现

队列接口声明:#ifndef __LINKLIST_QUEUE_H_#define __LINKLIST_QUEUE_H_struct unit { char data; struct unit* punit;};struct linklistqueue { int size; struct unit* phead; struct unit* ptail; void(*pf...

2018-12-26 21:00:08 152

原创 算法1-3-19答案

#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;struct node{ int value; struct node* pnext;};struct node* createlinklist(int length);void linklisttraverse(struct node* phead);void deletelas...

2018-12-26 20:49:35 258

原创 基于链表的栈实现

基于单链表的栈实现。栈接口定义:#ifndef __LINKLIST_STACK_H__#define __LINKLIST_STACK_H__#include &lt;stdio.h&gt;struct unit { char data; struct unit* punit;};struct linkliststack { int size; struct unit...

2018-12-26 14:50:33 420

原创 算法 1-3-4答案

array_stack.c 和array_stack.h 参展arraystack文章中的答案。#include “stack_array.h”#include &lt;unistd.h&gt;#include &lt;stdio.h&gt;int main (){ int result = test_parentheses_balance(); if(1 == result) {...

2018-12-24 16:22:16 242

原创 基于数组的扩缩容栈实现

参照算法第四版写的基于数组的可扩容与缩容的栈实现。非 -字符入栈,-字符出参。接口申明文件:stack_array.h#ifndef STACK_ARRAY_H#define STACK_ARRAY_Hextern int stack_array_size;void arraystackpush(char** parray, char value);char arraystackpo...

2018-12-24 15:37:57 174

原创 va_list、va_start和va_end的用法

在项目的代码中看到函数不定参数的使用,现在总结一下va_list、va_start和va_end三个宏的用法。c语言提供了函数的不定长参数使用,比如 void func(int a, …)。三个省略号,表示了不定长参数。注意:c标准规定了,函数必须至少有一个明确定义的参数,因此,省略号前面必须有至少一个参数。va_list宏定义了一个指针类型,这个指针类型指向参数列表中的参数。void va...

2018-09-26 16:44:02 11738 1

深入理解linux内核

深入理解linux内核,好资料哦。整理出来的,分享一下,大家都来下载吧

2013-02-20

空空如也

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

TA关注的人

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