- 博客(14)
- 资源 (3)
- 收藏
- 关注
原创 2-3树与红黑树
认识2-3树与红黑树2-3树2-3树如何维持平衡?红黑树2-3树认识红黑树之前,需要先了解2-3树,对红黑树的理解更直观。2-3树是绝对平衡的树,它满足二分搜索树的性质,每一个节点可以存放1个或者2个元素 33 / \ 18 , 28 40 / | \ / \ 9 , 10 20 30 35 50 , 60
2021-07-23 14:20:45 510
原创 Rust——并查集
Rust——并查集实现实现#![allow(unused)]//! 并查集:解决节点连接/关联问题/// 并查集 traittrait UF { fn is_connected(&mut self, p: usize, q: usize) -> bool; fn union_elements(&mut self, p: usize, q: usize); fn get_size(&self) -> usize;}/// 并查集结构
2021-07-15 12:53:31 237
原创 Rust——leetcode 677. 键值映射
use std::collections::HashMap;use std::rc::Rc;use std::cell::RefCell;// 节点定义struct Node {value: i32,next: HashMap<char, Rc<RefCell<Node>>>,}impl Node {pub fn new() -> Self {return Self {value: 0,next: HashMap::new(),};.
2021-07-14 17:15:25 148
原创 Rust——leetcode 211. 添加与搜索单词 - 数据结构设计
use std::collections::HashMap;use std::rc::Rc;use std::cell::RefCell;// 节点定义struct Node { is_word: bool, next: HashMap<char, Rc<RefCell<Node>>>,}impl Node { pub fn new_with_is_word(is_word: bool) -> Self { r
2021-07-14 17:11:50 123
原创 Rust_leetcode 208. 实现 Trie (前缀树)
字典树用于字符串处理代码实现#![allow(unused)]use std::collections::HashMap;use std::cell::RefCell;use std::rc::Rc;// 节点定义struct Node { is_word: bool, next: HashMap<char, Rc<RefCell<Node>>>,}impl Node { pub fn new_with_is_word(i
2021-07-14 17:09:45 468
原创 Rust——leetcode_307. 区域和检索 - 数组可修改
使用线段树来解决可修改的数组区域检索问题,时间复杂度为O(logn)struct NumArray { tree: SegmentTree}/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */impl NumArray { fn new(nums:
2021-07-14 12:06:28 139
原创 Rust——leetcode_303. 区域和检索 - 数组不可变
struct NumArray { sum: Vec<i32>}/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */impl NumArray { fn new(nums: Vec<i32>) -> Self {
2021-07-14 12:03:43 82
原创 Rust——线段树
Rust——线段树代码实现线段树是满二叉树,None代替没有元素的叶子节点线段树用于解决区间查询问题,所以不关心元素的增加删除操作。简单实现线段树的结构,所以这里没有写到修改线段树的元素查询时间复杂度O(logn),直接更新子节点的时间复杂度为O(n)代码实现#![allow(unused)]//! 线段树// 线段区间元素的融合方式trait 定义及其实现trait Merger { fn merge(&self, l: i32, r: i32) -> i32;
2021-07-14 10:09:38 206
原创 Rust——leetcode_剑指 Offer 40. 最小的k个数
使用最大堆的优先队列,解决最小的k个数问题最大堆优先队列先存储前k个元素,遍历剩下的元素,如果元素比队首元素小,就入队,否则忽略最中队列存储了最小的k个数impl Solution { pub fn get_least_numbers(arr: Vec<i32>, k: i32) -> Vec<i32> { let mut queue = PriorityQueue::new_priority(); for i in 0..k .
2021-07-08 12:25:21 128
原创 Rust——最大堆
Rust——最大堆实现排序测试实现#![allow(unused)]pub struct MaxHeap<E: PartialOrd + Copy> { data: Vec<E>}impl<E: PartialOrd + Copy> MaxHeap<E> { pub fn new_max_heap() -> MaxHeap<E> { Self { data: Vec::ne
2021-07-08 10:41:06 257
原创 Netty-心跳检测配置
管道链配置心跳状态handler,参数一:读超时,参数二:写超时,参数三:所有超时(0表示不监测)@Overrideprotected void initChannel(Channel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); //10S心跳检测连接 pip...
2021-06-27 13:55:48 200
原创 Netty-客户端-持续发送数据
模拟多客户端并发,将每个client作为一个线程 构造器中完成基本配置 线程run中连接服务器 finally释放内存 Handler连接完毕触发channelActive,开启新的线程作为传输者 传输者发送数据 发送数据完毕后,线程睡眠一定时间...
2021-06-27 13:54:48 1537
原创 Netty-客户端-触发重连
Netty连接,添加监听器 监听器重写operationComplete,连接失败10S后,重新建立连接 channel断开连接handler触发channelInactive 重新建立连接
2021-06-27 13:51:33 382
原创 Rust——二分查找法
实现一:循环fn search<E: PartialOrd>(data: Vec<E>, target: E) -> i32 { let mut l: i32 = 0; // 左闭右开区间 let mut r = data.len() as i32; while l < r { let mid = l + (r - l) / 2; if data[mid as usize] == target {
2021-06-27 13:47:14 748
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人