当前位置: 首页 > news >正文

科威网络做网站怎么样/培训心得体会

科威网络做网站怎么样,培训心得体会,王也经典语录名句,万能浏览器破解版文章目录 一、Map类型1.HashMaphashMap的简单插入entry().or_insert()更新hashMap 2.什么时候用HashMap3.HashMap中的键 二、BTreeMap1.什么时候用BTreeMap2.BTreeMap中的键 参考 一、Map类型 键值对数据又称字典数据类型 主要有两种 HashMap - BTreeMap 1.HashMap HashM…

文章目录

  • 一、Map类型
    • 1.HashMap
      • hashMap的简单插入
      • entry().or_insert()更新hashMap
    • 2.什么时候用HashMap
    • 3.HashMap中的键
  • 二、BTreeMap
    • 1.什么时候用BTreeMap
    • 2.BTreeMap中的键
  • 参考

一、Map类型

·键值对数据又称字典数据类型

·主要有两种

  • · HashMap
    ·- BTreeMap

1.HashMap

·HashMap<K,V>类型储存了一个键类型K对应一个值类型V的映射。它通过一个 哈希函数(hashing function)来实现映射,决定如何将键和值放入内存中。

·HashMap的数据和Vec一样在heap上

hashMap的简单插入

#![allow(unused)]
fn main() {use std::collections::HashMap;let mut scores = HashMap::new();scores.insert(String::from("Blue"), 10);scores.insert(String::from("Yellow"), 50);for (key, value) in &scores {println!("{}: {}", key, value);}
}
 cargo runCompiling abc v0.1.0 (/home/wangji/installer/rust/bobo/abc)Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.91sRunning `target/debug/abc`
Yellow: 50
Blue: 10

entry().or_insert()更新hashMap

直接覆盖


#![allow(unused)]
fn main() {
use std::collections::HashMap;let mut scores = HashMap::new();scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Blue"), 25);println!("{:?}", scores);
}

or_insert在没有key的情况下才插入

#![allow(unused)]
fn main() {use std::collections::HashMap;let mut scores = HashMap::new();scores.insert(String::from("Blue"), 10);scores.entry(String::from("Yellow")).or_insert(50);scores.entry(String::from("Blue")).or_insert(50);println!("{:?}", scores);
}
 cargo runBlocking waiting for file lock on package cacheBlocking waiting for file lock on package cacheCompiling abc v0.1.0 (/home/wangji/installer/rust/bobo/abc)Finished `dev` profile [unoptimized + debuginfo] target(s) in 13.96sRunning `target/debug/abc`
{"Blue": 10, "Yellow": 50}

or_inser根据旧值更新一个值,会返回插入的pair的value的引用

#![allow(unused)]
fn main() {use std::collections::HashMap;let text = "hello world wonderful world";let mut map = HashMap::new();for word in text.split_whitespace() {let count = map.entry(word).or_insert(0);*count += 1;}println!("{:?}", map);
}
 cargo runFinished `dev` profile [unoptimized + debuginfo] target(s) in 0.00sRunning `target/debug/abc`
{"hello": 1, "wonderful": 1, "world": 2}

2.什么时候用HashMap

·仅次于Vec的常用数据类型
·存储数据为键值对类型
需要查找的速度

  • in-memory cache

3.HashMap中的键

·因为要满足哈希函数,所以HashMap对键有特殊要求
·实现Hash、Eq、PartialEq
·一般结构体: #[derive(Debug, PartialEq, Hash, Eq)]

use std::collections::HashMap;// Hash Eq PartialEq
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Car {id: i32,price: i32,
}fn main() {let _int_map: HashMap<i32, i32> = HashMap::new();let _int_map: HashMap<i32, i32> = HashMap::with_capacity(10);// 通过数组来创建maplet mut car_map = HashMap::from([("Car1",Car {id: 1,price: 10000,},),("Car2", Car { id: 2, price: 4000 }),("Car3",Car {id: 3,price: 890000,},),]);// 打印实际是无序的for (k, v) in &car_map {println!("{k}:{:?}", v);}// getprintln!("Some {:?}", car_map.get("Car1"));println!("None {:?}", car_map.get("Car6"));// 覆盖性插入insertcar_map.insert("Car4",Car {id: 4,price: 80000,},);println!("{:?}", car_map);car_map.insert("Car4",Car {id: 5,price: 300000,},);println!("{:?}", car_map);// 只在键没有时插入// Entrycar_map.entry("Car4").or_insert(Car { id: 9, price: 9000 });println!("{:?}", car_map);// removecar_map.remove("Car4");println!("{:?}", car_map);car_map.entry("Car4").or_insert(Car { id: 9, price: 9000 });println!("{:?}", car_map);// 加上注释PartialEq, Eq, Hashlet mut car_map = HashMap::from([(Car {id: 1,price: 10000,},"Car1",),(Car { id: 2, price: 4000 }, "Car2"),(Car {id: 3,price: 890000,},"Car3",),]);println!("Car2: {:?}\n",car_map.get(&Car {id: 1,price: 10000}));for (car, name) in &car_map {println!("{:?}: {name}", car)}// Filter:会原地修改mapcar_map.retain(|c, _| c.price < 5000);println!("< 4000  {:?}", car_map);
}

编译及运行

 cargo runBlocking waiting for file lock on build directoryCompiling data_struct v0.1.0 (/home/wangji/installer/rust/data_struct/data_struct)Finished `dev` profile [unoptimized + debuginfo] target(s) in 13.52sRunning `target/debug/data_struct`
Car1:Car { id: 1, price: 10000 }
Car3:Car { id: 3, price: 890000 }
Car2:Car { id: 2, price: 4000 }
Some Some(Car { id: 1, price: 10000 })
None None
{"Car4": Car { id: 4, price: 80000 }, "Car2": Car { id: 2, price: 4000 }, "Car1": Car { id: 1, price: 10000 }, "Car3": Car { id: 3, price: 890000 }}
{"Car4": Car { id: 5, price: 300000 }, "Car2": Car { id: 2, price: 4000 }, "Car1": Car { id: 1, price: 10000 }, "Car3": Car { id: 3, price: 890000 }}
{"Car4": Car { id: 5, price: 300000 }, "Car2": Car { id: 2, price: 4000 }, "Car1": Car { id: 1, price: 10000 }, "Car3": Car { id: 3, price: 890000 }}
{"Car2": Car { id: 2, price: 4000 }, "Car1": Car { id: 1, price: 10000 }, "Car3": Car { id: 3, price: 890000 }}
{"Car4": Car { id: 9, price: 9000 }, "Car2": Car { id: 2, price: 4000 }, "Car1": Car { id: 1, price: 10000 }, "Car3": Car { id: 3, price: 890000 }}
Car2: Some("Car1")Car { id: 3, price: 890000 }: Car3
Car { id: 1, price: 10000 }: Car1
Car { id: 2, price: 4000 }: Car2
< 4000  {Car { id: 2, price: 4000 }: "Car2"}

二、BTreeMap

map的有序形式

内部基于BTree创建

1.什么时候用BTreeMap

·当你需要有序map时
·当你查找时,有序可以提供你的性能 (比如二分查找法)
·注意:有序是有代价的
·BTreeMap缓存效率和搜索中进行了折衷

2.BTreeMap中的键

·因为需要对键值排序所以需要Key实现

  • Ord
  • PartialOrd
use std::collections::BTreeMap;// Hash Eq PartialEq
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Car {id: i32,price: i32,
}impl Ord for Car {fn cmp(&self, other: &Self) -> std::cmp::Ordering {self.price.cmp(&other.price)}
}impl PartialOrd for Car {fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {Some(self.price.cmp(&other.price))}
}fn main() {let _int_map: BTreeMap<i32, i32> = BTreeMap::new();// let _int_map:BTreeMap<i32, i32> = BTreeMap::with_capacity(10);// 通过数组来创建maplet mut car_map = BTreeMap::from([("Car1",Car {id: 1,price: 10000,},),("Car2", Car { id: 2, price: 4000 }),("Car3",Car {id: 3,price: 890000,},),]);println!("{:#?}", car_map);println!("------------------------");let mut car_map = BTreeMap::from([(Car {id: 1,price: 10000,},1,),(Car { id: 2, price: 4000 }, 2),(Car {id: 3,price: 890000,},3,),]);for (k, v) in &car_map {println!("{:?}: {v}", k);}println!("----------------------");car_map.insert(Car {id: 4,price: 90000,},4,);for (k, v) in &car_map {println!("{:?}: {v}", k);}println!("----------------------");println!("{:?}",car_map.get(&Car {id: 1,price: 10000}));println!("{:?}", car_map.first_key_value());println!("{:?}", car_map.last_key_value());println!("----------------------");// removelet car = car_map.pop_first().unwrap();println!("{:?}", car);let car = car_map.pop_last().unwrap();println!("{:?}", car);println!("----------------------");for (k, v) in &car_map {println!("{:?}: {v}", k);}println!("----------------------");// remove(index)不建议你用car_map.remove(&Car {id: 1,price: 10000,});for (k, v) in &car_map {println!("{:?}: {v}", k);}println!("----------------------");car_map.clear();println!("{}", car_map.is_empty());
}

编译及运行

 cargo runCompiling data_struct v0.1.0 (/home/wangji/installer/rust/data_struct/data_struct)
warning: variable does not need to be mutable--> src/main.rs:27:9|
27 |     let mut car_map = BTreeMap::from([|         ----^^^^^^^|         ||         help: remove this `mut`|= note: `#[warn(unused_mut)]` on by defaultwarning: `data_struct` (bin "data_struct") generated 1 warning (run `cargo fix --bin "data_struct"` to apply 1 suggestion)Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.51sRunning `target/debug/data_struct`
{"Car1": Car {id: 1,price: 10000,},"Car2": Car {id: 2,price: 4000,},"Car3": Car {id: 3,price: 890000,},
}
------------------------
Car { id: 2, price: 4000 }: 2
Car { id: 1, price: 10000 }: 1
Car { id: 3, price: 890000 }: 3
----------------------
Car { id: 2, price: 4000 }: 2
Car { id: 1, price: 10000 }: 1
Car { id: 4, price: 90000 }: 4
Car { id: 3, price: 890000 }: 3
----------------------
Some(1)
Some((Car { id: 2, price: 4000 }, 2))
Some((Car { id: 3, price: 890000 }, 3))
----------------------
(Car { id: 2, price: 4000 }, 2)
(Car { id: 3, price: 890000 }, 3)
----------------------
Car { id: 1, price: 10000 }: 1
Car { id: 4, price: 90000 }: 4
----------------------
Car { id: 4, price: 90000 }: 4
----------------------
true

参考

  • Rust常用数据结构教程

相关文章:

Rust常用数据结构教程 Map

文章目录 一、Map类型1.HashMaphashMap的简单插入entry().or_insert()更新hashMap 2.什么时候用HashMap3.HashMap中的键 二、BTreeMap1.什么时候用BTreeMap2.BTreeMap中的键 参考 一、Map类型 键值对数据又称字典数据类型 主要有两种 HashMap - BTreeMap 1.HashMap HashM…...

<el-popover>可以展示select change改变值的时候popover 框会自动隐藏

一、问题定位 点击查看详细链接 element-plus 的 popover 组件&#xff0c;依赖 tooltip 组件&#xff1b;当 tooltip 的 trigger 的值不是 hover 时&#xff0c;会触发 close 事件&#xff1b;下拉框的 click 事件&#xff0c;触发了 tooltip 组件的 close 事件 总结一下&am…...

SQLI LABS | Less-37 POST-Bypass mysql_real_escape_string

关注这个靶场的其它相关笔记&#xff1a;SQLI LABS —— 靶场笔记合集-CSDN博客 0x01&#xff1a;过关流程 输入下面的链接进入靶场&#xff08;如果你的地址和我不一样&#xff0c;按照你本地的环境来&#xff09;&#xff1a; http://localhost/sqli-labs/Less-37/ 是一个登…...

数字后端零基础入门系列 | Innovus零基础LAB学习Day9

Module 16 Wire Editing 这个章节的学习目标是学习如何在innovus中手工画线&#xff0c;切断一根线&#xff0c;换孔&#xff0c;更改一条net shape的layer和width等等。这个技能是每个数字IC后端工程师必须具备的。因为项目后期都需要这些技能来修复DRC和做一些手工custom走线…...

深度学习:GLUE(General Language Understanding Evaluation)详解

GLUE&#xff08;General Language Understanding Evaluation&#xff09;详解 GLUE&#xff08;General Language Understanding Evaluation&#xff09;是一个用于评估和比较自然语言理解&#xff08;NLU&#xff09;系统的综合基准测试。它包括了一系列的任务&#xff0c;旨…...

基于Multisim直流稳压电源电路±9V、±5V(含仿真和报告)

【全套资料.zip】直流稳压电源电路9V、5VMultisim仿真设计数字电子技术 文章目录 功能一、Multisim仿真源文件二、原理文档报告资料下载【Multisim仿真报告讲解视频.zip】 功能 一般直流稳压电源都使用220伏市电作为电源&#xff0c;经过变压、整流、滤波后给稳压电路进行稳压…...

Vue Cli的配置中configureWebpack和chainWebpack的主要作用及区别是什么?

直接区别&#xff1a; configureWebpack项直接覆盖同名配置&#xff1b;chainWebpack项直接修改默认配置。 configureWebpack配置&#xff1a; // vue.config.js module.exports {configureWebpack: {plugins: [new MyAwesomeWebpackPlugin()]} }该代码段中的对象将会被web…...

ubuntu主机搭建sysroot交叉编译环境

ubuntu主机搭建sysroot交叉编译环境 主机是 ubuntu22.04 x86-64 hostubuntu22.04host-archx86-64host-cpui9-13900k 目标板是香橙派5b &#xff0c;ubuntu22.04,aarch64 ,cpu rk3588s targetubuntu22.04target-archaarch64target-cpurk3588s 安装 qemu-user-static 进入 …...

Python注意力机制Attention下CNN-LSTM-ARIMA混合模型预测中国银行股票价格|附数据代码...

全文链接&#xff1a;https://tecdat.cn/?p38195 股票市场在经济发展中占据重要地位。由于股票的高回报特性&#xff0c;股票市场吸引了越来越多机构和投资者的关注。然而&#xff0c;由于股票市场的复杂波动性&#xff0c;有时会给机构或投资者带来巨大损失。考虑到股票市场的…...

实验三 JDBC数据库操作编程(设计性)

实验三 JDBC数据库操作编程&#xff08;设计性&#xff09; 实验目的 掌握JDBC的数据库编程方法。掌握采用JDBC完成数据库链接、增删改查&#xff0c;以及操作封装的综合应用。实验要求 本实验要求每个同学单独完成&#xff1b;调试程序要记录调试过程中出现的问题及解决办法…...

各种环境换源教程

目录 pip 换源相关命令永久换源1. 命令行换源2. 配置文件换源 临时换源使用官方源使用镜像源 报错参考 npm换源相关命令永久换源1. 命令行换源2. 配置文件换源 pip 换源 相关命令 更新 pip 本身 首先&#xff0c;为了确保你使用的是最新版本的 pip&#xff0c;可以通过以下命…...

Rust项目中的Labels

姊妹篇: Go项目中的Labels 按照issue数量从多到少排序: https://github.com/rust-lang/rust/labels?page2&sortcount-desc https://github.com/rust-lang/rust/labels/A-contributor-roadblock 第1页: 标签/中文说明数字T-compiler/编译器Relevant to the compiler tea…...

Jmeter的安装和使用

使用场景&#xff1a; 我们需要对某个接口进行压力测试&#xff0c;在多线程环境下&#xff0c;服务的抗压能力&#xff1b;还有就是关于分布式开发需要测试多线程环境下数据的唯一性。 解决方案: jmeter官网连接&#xff1a;Apache JMeter - Apache JMeter™ 下载安装包 配…...

初识Electron 进程通信

概述 Electron chromium nodejs native API&#xff0c;也就是将node环境和浏览器环境整合到了一起&#xff0c;这样就构成了桌面端&#xff08;chromium负责渲染、node负责操作系统API等&#xff09; 流程模型 预加载脚本&#xff1a;运行在浏览器环境下&#xff0c;但是…...

go语言中的通道(channel)详解

在 Go 语言中&#xff0c;通道&#xff08;channel&#xff09; 是一种用于在 goroutine&#xff08;协程&#xff09;之间传递数据的管道。通道具有类型安全性&#xff0c;即它只能传递一种指定类型的数据。通道是 Go 并发编程的重要特性&#xff0c;能够让多个 goroutine 之间…...

【JS】内置类型的相关问题

我是目录 引言内置类型undefined与nullnull和undefined的区别字符串转换为字符串数字0.1+0.2不等于0.3NaNBigInt大数相加问题原生函数(封箱与解封)判断类型的方法typeofinstanceofObject.prototype.toString.callconstructor类型转换toStringtoNumbertoBoolean显式强制类型转…...

Mac上无法访问usr/local的文件

sudo chmod 755 /usr/loca 最后用百度提供的方法解决了...

http 常见状态码

1xx 信息&#xff0c;表示临时响应并需要请求者继续执行操作 2xx 成功&#xff0c;操作被成功接收并处理 3xx 表示要完成请求&#xff0c;需要进一步操作。通常&#xff0c;这些状态码用来重定向 4xx 客户端错误&#xff0c;请求包含语法错误或无法完成请求 5xx 服务…...

代码训练营 day59|并查集

前言 这里记录一下陈菜菜的刷题记录&#xff0c;主要应对25秋招、春招 个人背景 211CS本CUHK计算机相关硕&#xff0c;一年车企软件开发经验 代码能力&#xff1a;有待提高 常用语言&#xff1a;C 系列文章目录 第59天 &#xff1a;第十一章&#xff1a;图论part05 文章目录…...

Node.js——fs模块-路径补充说明

1、相对路径&#xff1a; ./座右铭.txt 当前目录下的座右铭.txt座右铭.txt 等效于上面的写法../座右铭.txt 当前目录的上一级目录中的座右铭.txt 2、绝对路径 D&#xff1a;/Program File Windows系统下的绝对路径/usr/bin Linux系统…...

华为ENSP--ISIS路由协议

项目背景 为了确保资源共享、办公自动化和节省人力成本&#xff0c;公司E申请两条专线将深圳总部和广州、北京两家分公司网络连接起来。公司原来运行OSFP路由协议&#xff0c;现打算迁移到IS-IS路由协议&#xff0c;张同学正在该公司实习&#xff0c;为了提高实际工作的准确性和…...

论软件可靠性设计及其应用

摘要 2023 年 3 月&#xff0c;我所在的公司承接了某智慧加油站平台的建设工作。该项目旨在帮助加油站提升运营效率、降低运营成本和提高销售额。我在该项目中担任系统架构设计师&#xff0c;负责整个项目的架构设计工作。 本文结合我在该项目中的实践&#xff0c;详细论述了…...

Android中桌面小部件framework层使用到的设计模式

在Android中&#xff0c;桌面小部件&#xff08;App Widget&#xff09;的Framework层采用了多种设计模式&#xff0c;以实现模块化、可维护性和高效的交互。 以下是Android桌面小部件Framework层中常用的设计模式及其具体应用&#xff1a; 1. 观察者模式&#xff08;Observe…...

【JavaEE进阶】HTML

本节⽬标 认识 HTML 的基本结构, 学习常⽤的 HTML 标签. 一 HTML基础 1.什么是HTML HTML(Hyper Text Markup Language), 超⽂本标记语⾔. 超⽂本: ⽐⽂本要强⼤. 通过链接和交互式⽅式来组织和呈现信息的⽂本形式. 不仅仅有⽂本, 还可能包含图⽚, ⾳频, 或者⾃已经审阅过它…...

ElasticSearch 添加IK分词器

ElasticSearch 添加IK分词器 前言一、IK分词器的算法二、Ik分词器的下载安装&#xff08;Winows 版本&#xff09;三、Ik分词器的下载安装&#xff08;Linux 版本&#xff09;四、验证测试&#xff08;postman工具&#xff09;测试 ik_smart 分词算法测试 ik_max_word 分词算法…...

可视化建模与UML《顺序图实验报告》

旷野的规则是永不回头。 一、实验目的&#xff1a; 1、熟悉顺序图的构件事物。 2、熟悉发送者与接受者的关系 3、熟练掌握描绘顺序图 4、加深对顺序图的理解和应用能力 二、实验环境&#xff1a; window7 | 10 | 11 EA15 三、实验内容&#xff1a; 据如下描述绘制顺序图&…...

Mac的极速文件搜索工具,高效管理文件

Mac的资源管理可以说是许多转Mac的朋友用不明白的一点了&#xff0c;访达怎么用&#xff0c;文件怎么找&#xff0c;为什么找不到&#xff0c;非常的头大 All作为Mac上的极速文件搜索管理工具&#xff0c;有效的为文件查找困难的用户解决难题 基于极速搜索引擎&#xff0c;快…...

公开仓库改私有再配置公钥后Git拉取仍需要输入用户名的问题

问题描述&#xff1a;git拉取私有仓库需要输入用户名和密码 我之前写了一个脚本用来定时自动拉取远程仓库更新本地仓库&#xff0c;后来将这个远程仓库改成私有后执行脚本就会需要输入用户名和密码。 [rootLH2020 ~]# ./sync_repo.sh 正在从远程仓库拉取最新更改… Username f…...

工作流初始错误 泛微提交流程提示_泛微协同办公平台E-cology8.0版本后台维护手册(11)–系统参数设置

工作流初始错误 泛微提交流程提示_泛微协同办公平台E-cology8.0版本后台维护手册(11)–系统参数设置...-CSDN博客 工作流初始错误 泛微提交流程提示_泛微OA 工作流WebService接口使用说明 工作流初始错误 泛微提交流程提示_泛微OA 工作流WebService接口使用说明-CSDN博客 工作…...

window下安装rust 及 vscode配置

安装 安装mingw64 &#xff08;c语言环境 选择posix-ucrt&#xff09; ucrt:通用c运行时库配置mingw64/bin的路径到环境变量中在cmd窗口中输入命令 "gcc -v" 4. 下载Rust安装程序 安装 Rust - Rust 程序设计语言 5. 配置rustup和cargo目录 &#xff08;cargo是包管…...