Pure Soul

Golang

Diameter of Tree

Definition of diameter In a given tree, the diameter is defined as the longest path between any two nodes. For instance, the diameter of the tree shown below is 4, which is formed by the paths between nodes (1, 8), (2, 8), and (5, 8). How can we obtain diamete…

2024年7月7日 0条评论 960点热度 2人点赞 ycq 阅读全文
flink

Timer on Flink

Timer on ProcessFunction and KeyedProcessFunction Flink distinguishes between two key notions of time: processing time and event time. Processing time refers to the system time at which an event is processed, whereas event time is explicitly defined or configu…

2024年5月29日 0条评论 1502点热度 0人点赞 ycq 阅读全文
flink

Loading data periodically in Flink

Stream API (SourceFunction, AbstractSourceFunction and RichSourceFunction) in Flink In Flink's streaming API, there is a critical interface named Function, which extends Serializable: public interface Function extends Serializable { } Nearly all streaming APIs…

2024年5月26日 0条评论 1701点热度 1人点赞 ycq 阅读全文
未分类

Maximum Manhattan Distance of Two Points in Points Set

Manhattan Distance Definition: The Manhattan distance between two points (x_1, y_1) and (x_2, y_2) in a 2D plane is defined as dis = |x_1 - x_2| + |y_1 - y_2|, where | \cdot | denotes the absolute value. Problem Definition Given a set of points {p_1, p_2, \ldo…

2024年4月1日 0条评论 1935点热度 0人点赞 ycq 阅读全文
python

Dynamic Segment Tree

Why Dynamic Segment Tree? As know for segment tree, the space complexity is is up to 4n, which n is upper bound of data range. However, :-(, n some times becomes very large, such as 10^9 or infinity. OOM problem would occur if we allocate 4n size array for que…

2023年12月16日 0条评论 1079点热度 0人点赞 ycq 阅读全文
杂谈

Golang--GMP(Goroutine, Machine, Processor)模型

前言 Goroutine是Golang中实现的协程,它保证了Golang的高并发的可用性,这些Goroutine分配、负载、调度到处理器上采用的是G-M-P模型。 进程、线程、Goroutine 进程是操作系统进行资源分配调度的最小单元,而线程则是CPU进行调度的最小单元。进程和线程的切换管理需要操作系统接管,因此在切换时会涉及到CPU的上下文切换,会导致切换的成本较大。而Goroutine作为用户级线程在切换时有用户控制,因此切换成本没有内核级线程大。并且,内核级线程是抢占式调度,但是用户级线程是协作式调度(一个…

2022年7月11日 0条评论 1001点热度 0人点赞 ycq 阅读全文
杂谈

非技术篇-7 Habits of Highly Effective People [By Stephen R. Covey]

引言 Covey在书中用一个小例子描述了“个人看法的重要性”,他儿子在学校的表现不尽人意,做父母的经常鼓励孩子,然而却是于事无补,随着Covey对儿子的看法转变,即便是不刻意鼓励孩子,他也能飞快的进步。也即引出了书中最为重要的观点:“为了达成真正的改变,必须对自我认知做出改变,而不仅仅停留在表面” 1. Be Proactive 消极对待事物,诸如“我不行”、“直接摆烂得了”等一系列态度,是效率低下的元凶。相反的,积极主动是对提高自身效率有重要帮助。 如果每次遇到问题都从外部找原因,那么会对遇到的困难、问题形成应激…

2022年5月31日 0条评论 838点热度 0人点赞 ycq 阅读全文
系统设计

系统设计之——Twitter时间线、搜索功能

Timeline & Search 简介 系统设计中,时间线(timeline)功能是十分常见的,诸如朋友圈,微博,Twitter等社交平台都会涉及到,主要功能就是按时间线看到已经关注的人发送的消息。而搜索功能则是公开社交平台的重要功能。 Pull vs. Push 为了实现时间线的功能,可以采用“推”或者“拉”的手段进行实现。比如某位用户发送了一条消息,那么系统将该消息推送给所有关注者;或者,将消息暂存,等待关注的用户查看的时候,再由用户自己吧消息取出。前者是Push,后者是Pull。 系统读写峰值 以T…

2022年1月25日 0条评论 1973点热度 0人点赞 ycq 阅读全文
Golang

API限速设计

给定一个公共API,限制每个用户每秒只能调用1000次,如何实现?这个一个经典的API限速问题(API rate limiting)。 初始想法 最朴素的想法就是给每一个用户配额,此时为Q,在第一次调用的时候分配给用户,然后在接下来的时间段,如果访问的此时大于Q,就直接拒绝用户的调用。随后经过一段时间后,再次分配Q。 type tf struct { limits int lastAsk time.Time } var GAP time.Duration = time.Second * 10 // 单次访问限制在1…

2022年1月24日 0条评论 1016点热度 0人点赞 ycq 阅读全文
Golang

雪花算法及Golang实现

雪花算法能解决什么问题? 雪花算法能够生成全局唯一的ID编码作为其他地方的标记。且生成一系列的ID满足如下的性质: 生成的系列ID是递增的 高可用性:任何时候都能够生成唯一的ID 再高并发的条件下也能够保证服务 SnowFlake的组成 最高位是符号位,始终为0 41位的时间戳,精度位毫秒级,可使用69年 10位的机器码,支持1024个节点 12位的id,每毫秒可以生成4096个id 12位的计数序列号,自增。同一节点,同一毫秒最多产生4096个序号 SnowFlake的golang实现 package snow …

2022年1月2日 0条评论 1409点热度 0人点赞 ycq 阅读全文
12345

COPYRIGHT © 2021 oo2ee.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS