Rust vs Go:常用语法对比
这个网站 可以列出某门编程语言的常用语法,也可以对比两种语言的基本语法差别。
在此对比Go和Rust
1. Print Hello World
打印Hello World
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
fn main() {
println!("Hello World");
}
Rust 输出文字的方式主要有两种:println!() 和 **print!()**。这两个"函数"都是向命令行输出字符串的方法,区别仅在于前者会在输出的最后附加输出一个换行符。当用这两个"函数"输出信息的时候,第一个参数是格式字符串,后面是一串可变参数,对应着格式字符串中的"占位符",这一点与 C 语言/ Go语言 中的 printf 函数很相似。但是,Rust 中格式字符串中的占位符不是"% + 字母"的形式,而是一对 {}。
2. Print Hello 10 times
打印10次Hello World
package main
import (
"fmt"
)
func main() {
for i := 0; i < 10; i++ {
fmt.Println("Hello")
}
}
or
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Print(strings.Repeat("Hello\n", 10))
}
fn main() {
for _ in 0..10 {
println!("Hello");
}
}
or
fn main() {
print!("{}", "Hello\n".repeat(10));
}
3. Create a procedure
Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)
创建一个方法,没有返回值,打印一些内容
package main
import "fmt"
func finish(name string) {
fmt.Println("My job here is done. Good bye " + name)
}
func main() {
finish("Tony")
}
fn main(){
finish("Buddy")
}
fn finish(name : &str) {
println!("My job here is done. Goodbye {}", name);
}
4. Create a function which returns the square of an integer
创建一个函数,返回一个整数的平方
func square(x int) int {
return x*x
}
fn square(x: u32) -> u32 {
x * x
}
fn main() {
let sq = square(9);
println!("{}", sq);
}
5. Create a 2D Point data structure
Declare a container type for two floating-point numbers x and y
声明一个容器类型,有x、y两个浮点数
package main
import "fmt"
type Point struct {
x, y float64
}
func main() {
p1 := Point{}
p2 := Point{2.1, 2.2}
p3 := Point{
y: 3.1,
x: 3.2,
}
p4 := &Point{
x: 4.1,
y: 4.2,
}
fmt.Println(p1)
fmt.Println(p2)
fmt.Println(p3)
fmt.Println(p4)
}
输出
{0 0}
{2.1 2.2}
{3.2 3.1}
&{4.1 4.2}
use std::fmt;
struct Point {
x: f64,
y: f64,
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}
fn main() {
let p = Point { x: 2.0, y: -3.5 };
println!("{}", p);
}
or
use std::fmt;
struct Point(f64, f64);
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.0, self.1)
}
}
fn main() {
let p = Point(2.0, -3.5);
println!("{}", p);
}
6. Iterate over list values
Do something with each item x of an array-like collection items, regardless indexes.
遍历列表的值
for _, x := range items {
doSomething(x)
}
package main
import (
"fmt"
)
func main() {
items := []int{11, 22, 33}
for _, x := range items {
doSomething(x)
}
}
func doSomething(i int) {
fmt.Println(i)
}
输出
11
22
33
fn main() {
let items = vec![11, 22, 33];
for x in items {
do_something(x);
}
}
fn do_something(n: i64) {
println!("Number {}", n)
}
or
fn main() {
let items = vec![11, 22, 33];
items.into_iter().for_each(|x| do_something(x));
}
fn do_something(n: i64) {
println!("Number {}", n)
}
7. Iterate over list indexes and values
遍历列表的索引和值
package main
import "fmt"
func main() {
items := []string{
"oranges",
"apples",
"bananas",
}
for i, x := range items {
fmt.Printf("Item %d = %v \n", i, x)
}
}
输出
Item 0 = oranges
Item 1 = apples
Item 2 = bananas
fn main() {
let items = ["a", "b", "c"];
for (i, x) in items.iter().enumerate() {
println!("Item {} = {}", i, x);
}
}
or
fn main() {
let items = ["a", "b", "c"];
items.iter().enumerate().for_each(|(i, x)| {
println!("Item {} = {}", i, x);
});
}
8. Initialize a new map (associative array)
Create a new map object x, and provide some (key, value) pairs as initial content.
创建一个新的map,提供一些键值对 作为初始内容
package main
import "fmt"
func main() {
x := map[string]int{"one": 1, "two": 2}
fmt.Println(x)
}
输出
map[one:1 two:2]
use std::collections::BTreeMap;
fn main() {
let mut x = BTreeMap::new();
x.insert("one", 1);
x.insert("two", 2);
println!("{:?}", x);
}
输出为:
("one", 1)
("two", 2)
or
use std::collections::HashMap;
fn main() {
let x: HashMap<&str, i32> = [
("one", 1),
("two", 2),
].iter().cloned().collect();
println!("{:?}", x);
}
输出为:
("two", 2)
("one", 1)
分 BTreeMap 和 HashMap,且都需要use进来; 前者无序,后者有序
9. Create a Binary Tree data structure
The structure must be recursive because left child and right child are binary trees too. A node has access to children nodes, but not to its parent.
创建一个二叉树
type BinTree struct {
Value valueType
Left *BinTree
Right *BinTree
}
package main
import "fmt"
type BinTree struct {
Value int
Left *BinTree
Right *BinTree
}
func inorder(root *BinTree) {
if root == nil {
return
}
inorder(root.Left)
fmt.Printf("%d ", root.Value)
inorder(root.Right)
}
func main() {
root := &BinTree{1, nil, nil}
root.Left = &BinTree{2, nil, nil}
root.Right = &BinTree{3, nil, nil}
root.Left.Left = &BinTree{4, nil, nil}
root.Left.Right = &BinTree{5, nil, nil}
root.Right.Right = &BinTree{6, nil, nil}
root.Left.Left.Left = &BinTree{7, nil, nil}
inorder(root)
}
输出
7 4 2 5 1 3 6
struct BinTree<T> {
value: T,
left: Option<Box<BinTree<T>>>,
right: Option<Box<BinTree<T>>>,
}
10. Shuffle a list
Generate a random permutation of the elements of list x
随机排序一个list
package main
import (
"fmt"
"math/rand"
)
func main() {
x := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
for i := range x {
j := rand.Intn(i + 1)
x[i], x[j] = x[j], x[i]
}
fmt.Println(x)
}
输出
[f e c g h a d b]
or
package main
import (
"fmt"
"math/rand"
)
func main() {
x := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
y := make([]string, len(x))
perm := rand.Perm(len(x))
for i, v := range perm {
y[v] = x[i]
}
fmt.Println(y)
}
输出
[f h c g b a d e]
rand.Perm(x)挺有意思的一个函数,perm应该是permutation的缩写,即置换,排列。
会输出一个从0-(x-1)随机顺序排列的数组,类似洗牌,总数不变,打乱顺序
or
package main
import (
"fmt"
"math/rand"
)
func main() {
x := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
rand.Shuffle(len(x), func(i, j int) {
x[i], x[j] = x[j], x[i]
})
fmt.Println(x)
}
输出
[f a h b c d g e]
or
package main
import (
"fmt"
"math/rand"
)
func main() {
x := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
for i := len(x) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
x[i], x[j] = x[j], x[i]
}
fmt.Println(x)
}
输出
[g d a h e f c b]
extern crate rand;
use rand::{Rng, StdRng};
let mut rng = StdRng::new().unwrap();
rng.shuffle(&mut x);
or
use rand::seq::SliceRandom;
use rand::thread_rng;
fn main() {
let mut x = [1, 2, 3, 4, 5];
println!("Unshuffled: {:?}", x);
let mut rng = thread_rng();
x.shuffle(&mut rng);
println!("Shuffled: {:?}", x);
}
11. Pick a random element from a list
从列表中选择一个随机元素
package main
import (
"fmt"
"math/rand"
)
var x = []string{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}
func main() {
fmt.Println(x[rand.Intn(len(x))])
}
输出
fuligin
or
package main
import (
"fmt"
"math/rand"
)
type T string
func pickT(x []T) T {
return x[rand.Intn(len(x))]
}
func main() {
var list = []T{"bleen", "fuligin", "garrow", "grue", "hooloovoo"}
fmt.Println(pickT(list))
}
输出
fuligin
use rand::{self, Rng};
fn main() {
let x = vec![11, 22, 33];
let choice = x[rand::thread_rng().gen_range(0..x.len())];
println!("I picked {}!", choice);
}
or
use rand::seq::SliceRandom;
fn main() {
let x = vec![11, 22, 33];
let mut rng = rand::thread_rng();
let choice = x.choose(&mut rng).unwrap();
println!("I picked {}!", choice);
}
12. Check if list contains a value
Check if list contains a value x. list is an iterable finite container.
检查列表中是否包含一个值
package main
import "fmt"
func Contains(list []T, x T) bool {
for _, item := range list {
if item == x {
return true
}
}
return false
}
type T string
func main() {
list := []T{"a", "b", "c"}
fmt.Println(Contains(list, "b"))
fmt.Println(Contains(list, "z"))
}
输出
true
false
fn main() {
let list = [10, 40, 30];
{
let num = 30;
if list.contains(&num) {
println!("{:?} contains {}", list, num);
} else {
println!("{:?} doesn't contain {}", list, num);
}
}
{
let num = 42;
if list.contains(&num) {
println!("{:?} contains {}", list, num);
} else {
println!("{:?} doesn't contain {}", list, num);
}
}
}
or
fn main() {
let list = [10, 40, 30];
let x = 30;
if list.iter().any(|v| v == &x) {
println!("{:?} contains {}", list, x);
} else {
println!("{:?} doesn't contain {}", list, x);
}
}
or
fn main() {
let list = [10, 40, 30];
let x = 30;
if (&list).into_iter().any(|v| v == &x) {
println!("{:?} contains {}", list, x);
} else {
println!("{:?} doesn't contain {}", list, x);
}
}
13. Iterate over map keys and values
Access each key k with its value x from an associative array mymap, and print them
遍历关联数组中的每一对 k-v, 并打印出它们
package main
import "fmt"
func main() {
mymap := map[string]int{
"one": 1,
"two": 2,
"three": 3,
"four": 4,
}
for k, x := range mymap {
fmt.Println("Key =", k, ", Value =", x)
}
}
输出
Key = two , Value = 2
Key = three , Value = 3
Key = four , Value = 4
Key = one , Value = 1
use std::collections::BTreeMap;
fn main() {
let mut mymap = BTreeMap::new();
mymap.insert("one", 1);
mymap.insert("two", 2);
mymap.insert("three", 3);
mymap.insert("four", 4);
for (k, x) in &mymap {
println!("Key={key}, Value={val}", key = k, val = x);
}
}
14. Pick uniformly a random floating point number in [a..b)
Pick a random number greater than or equals to a, strictly inferior to b. Precondition : a < b.
选出一个随机的浮点数,大于或等于a,严格小于b,且a< b
package main
import (
"fmt"
"math/rand"
)
func main() {
x := pick(-2.0, 6.5)
fmt.Println(x)
}
func pick(a, b float64) float64 {
return a + (rand.Float64() * (b - a))
}
输出
3.1396124478267664
extern crate rand;
use rand::{thread_rng, Rng};
fn main() {
let (a, b) = (1.0, 3.0);
let c = thread_rng().gen_range(a..b);
println!("{}", c);
}
15. Pick uniformly a random integer in [a..b]
Pick a random integer greater than or equals to a, inferior or equals to b. Precondition : a < b.
选出一个随机的整数,大于或等于a,小于或等于b,且a< b
package main
import (
"fmt"
"math/rand"
)
func main() {
x := pick(3, 7)
// Note that in the Go Playground, time and random don't change very often.
fmt.Println(x)
}
func pick(a, b int) int {
return a + rand.Intn(b-a+1)
}
输出
4
fn pick(a: i32, b: i32) -> i32 {
let between = Range::new(a, b);
let mut rng = rand::thread_rng();
between.ind_sample(&mut rng)
}
or
use rand::distributions::Distribution;
use rand::distributions::Uniform;
fn main() {
let (a, b) = (3, 5);
let x = Uniform::new_inclusive(a, b).sample(&mut rand::thread_rng());
println!("{}", x);
}
17. Create a Tree data structure
The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.
创建树数据结构, 该结构必须是递归的。一个节点可以有零个或多个子节点,节点可以访问子节点,但不能访问其父节点
type Tree struct {
Key keyType
Deco valueType
Children []*Tree
}
package main
import "fmt"
type Tree struct {
Key key
Deco value
Children []*Tree
}
type key string
type value string
func (t *Tree) String() string {
str := "("
str += string(t.Deco)
if len(t.Children) == 0 {
return str + ")"
}
str += " ("
for _, child := range t.Children {
str += child.String()
}
str += "))"
return str
}
func (this *Tree) AddChild(x key, v value) *Tree {
child := &Tree{Key: x, Deco: v}
this.Children = append(this.Children, child)
return child
}
func main() {
tree := &Tree{Key: "Granpa", Deco: "Abraham"}
subtree := tree.AddChild("Dad", "Homer")
subtree.AddChild("Kid 1", "Bart")
subtree.AddChild("Kid 2", "Lisa")
subtree.AddChild("Kid 3", "Maggie")
fmt.Println(tree)
}
输出
(Abraham ((Homer ((Bart)(Lisa)(Maggie)))))
use std::vec;
struct Node<T> {
value: T,
children: Vec<Node<T>>,
}
impl<T> Node<T> {
pub fn dfs<F: Fn(&T)>(&self, f: F) {
self.dfs_helper(&f);
}
fn dfs_helper<F: Fn(&T)>(&self, f: &F) {
(f)(&self.value);
for child in &self.children {
child.dfs_helper(f);
}
}
}
fn main() {
let t: Node<i32> = Node {
children: vec![
Node {
children: vec![
Node {
children: vec![],
value: 14
}
],
value: 28
},
Node {
children: vec![],
value: 80
}
],
value: 50
};
t.dfs(|node| { println!("{}", node); });
}
输出:
50
28
14
80
18. Depth-first traversing of a tree
Call a function f on every node of a tree, in depth-first prefix order
树的深度优先遍历。按照深度优先的前缀顺序,在树的每个节点上调用函数f
package main
import . "fmt"
func (t *Tree) Dfs(f func(*Tree)) {
if t == nil {
return
}
f(t)
for _, child := range t.Children {
child.Dfs(f)
}
}
type key string
type value string
type Tree struct {
Key key
Deco value
Children []*Tree
}
func (this *Tree) AddChild(x key, v value) {
child := &Tree{Key: x, Deco: v}
this.Children = append(this.Children, child)
}
func NodePrint(node *Tree) {
Printf("%v (%v)\n", node.Deco, node.Key)
}
func main() {
tree := &Tree{Key: "Granpa", Deco: "Abraham"}
tree.AddChild("Dad", "Homer")
tree.Children[0].AddChild("Kid 1", "Bart")
tree.Children[0].AddChild("Kid 2", "Lisa")
tree.Children[0].AddChild("Kid 3", "Maggie")
tree.Dfs(NodePrint)
}
输出
Abraham (Granpa)
Homer (Dad)
Bart (Kid 1)
Lisa (Kid 2)
Maggie (Kid 3)
use std::vec;
struct Tree<T> {
children: Vec<Tree<T>>,
value: T
}
impl<T> Tree<T> {
pub fn new(value: T) -> Self{
Tree{
children: vec![],
value
}
}
pub fn dfs<F: Fn(&T)>(&self, f: F) {
self.dfs_helper(&f);
}
fn dfs_helper<F: Fn(&T)>(&self, f: &F) {
(f)(&self.value);
for child in &self.children {
child.dfs_helper(f);
}
}
}
fn main() {
let t: Tree<i32> = Tree {
children: vec![
Tree {
children: vec![
Tree {
children: vec![],
value: 14
}
],
value: 28
},
Tree {
children: vec![],
value: 80
}
],
value: 50
};
t.dfs(|node| { println!("{}", node); });
}
输出:
50
28
14
80
19. Reverse a list
Reverse the order of the elements of list x. This may reverse "in-place" and destroy the original ordering.
反转链表
package main
import "fmt"
func main() {
s := []int{5, 2, 6, 3, 1, 4}
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
fmt.Println(s)
}
输出
[4 1 3 6 2 5]
fn main() {
let x = vec!["Hello", "World"];
let y: Vec<_> = x.iter().rev().collect();
println!("{:?}", y);
}
输出:
["World", "Hello"]
or
fn main() {
let mut x = vec![1,2,3];
x.reverse();
println!("{:?}", x);
}
输出:
[3, 2, 1]
20. Return two values
Implement a function search which looks for item x in a 2D matrix m. Return indices i, j of the matching cell. Think of the most idiomatic way in the language to return the two values at the same time.
实现在2D矩阵m中寻找元素x,返回匹配单元格的索引 i,j
package main
import "fmt"
func search(m [][]int, x int) (bool, int, int) {
for i := range m {
for j, v := range m[i] {
if v == x {
return true, i, j
}
}
}
return false, 0, 0
}
func main() {
matrix := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
for x := 1; x <= 11; x += 2 {
found, i, j := search(matrix, x)
if found {
fmt.Printf("matrix[%v][%v] == %v \n", i, j, x)
} else {
fmt.Printf("Value %v not found. \n", x)
}
}
}
输出
matrix[0][0] == 1
matrix[0][2] == 3
matrix[1][1] == 5
matrix[2][0] == 7
matrix[2][2] == 9
Value 11 not found.
fn search<T: Eq>(m: &Vec<Vec<T>>, x: &T) -> Option<(usize, usize)> {
for (i, row) in m.iter().enumerate() {
for (j, column) in row.iter().enumerate() {
if *column == *x {
return Some((i, j));
}
}
}
None
}
fn main() {
let a = vec![
vec![0, 11],
vec![22, 33],
vec![44, 55],
];
let hit = search(&a, &33);
println!("{:?}", hit);
}
输出:
Some((1, 1))
本文由 mdnice 多平台发布
相关文章:
Rust vs Go:常用语法对比
这个网站 可以列出某门编程语言的常用语法,也可以对比两种语言的基本语法差别。 在此对比Go和Rust 1. Print Hello World 打印Hello World package mainimport "fmt"func main() { fmt.Println("Hello World")} fn main() { println!("…...

Vlan端口隔离(第二十四课)
一、端口隔离 1、端口隔离技术概述 1)端口隔离技术出现背景:为了实现报文之间的二层隔离,可以将不同的端口加入不同的VLAN,但这样会浪费有限的VLAN ID资源。 2)端口隔离的作用:采用端口隔离功能,可以实现同一VLAN内端口之间的隔离。 3)如何实现端口隔离功能:只需要…...

js实现框选截屏功能
实现的思路大概就是,先将dom转化为canvas画布,再对canvas进行裁切,然后通过canvas api生成图片,这里用到了一个库html2canvas 效果如图: 首先实现框选效果: const mousedownEvent (e) > {moveX 0;mo…...
Manjaro Linux 连接公司的 VPN 网络
注意:如果你公司的 VPN 网络是在苹果下使用的,本文可能不适用(苹果系统不支持 PPTP)。 用 Linux 和用 Windows/macOS 不一样,它真的需要用户操心很多东西。比如怎么连接公司的 VPN 网络…… 我是折腾了挺久࿰…...
Ama no Jaku
登录—专业IT笔试面试备考平台_牛客网 题目大意:有一个n*n且仅由0和1构成的矩阵,每次操作可以将一整行或一整列的所有数取反,问能否使所有行中构成的最小数>所有列中构成的最大数 1<n<2000 思路:首先,如果…...

视频基础知识
1.视频比特率 视频的比特率是指传输过程中单位时间传输的数据量。可以理解为视频的编码采样率。单位是kbps,即每秒千比特。视频比特率是决定视频清晰度的一个重要指标。比特率越高,视频越清晰,但数据量也会越大。比如一部100分钟的电影&#…...
安全渗透初级知识总结
Day1: xss详解:web攻防之XSS攻击详解——XSS简介与类型 - 知乎 (zhihu.com) Cookie:身份验证 网页元素属性: id: class:样式名称 console.log(div_class);----打印标签 tabindex"0"---这是…...

rocketmq客户端本地日志文件过大调整配置(导致pod缓存cache过高)
现象 在使用rocketmq时,发现本地项目中文件越来越大,查找发现在/home/root/logs/rocketmqlog目录下存在大量rocketmq_client.log日志文件。 配置调整 开启slf4j日志模式,在项目启动项中增加-Drocketmq.client.logUseSlf4jtrue因为配置使用的…...

Unity进阶-ui框架学习笔记
文章目录 Unity进阶-ui框架学习笔记 Unity进阶-ui框架学习笔记 笔记来源课程:https://study.163.com/course/courseMain.htm?courseId1212756805&_trace_c_p_k2_8c8d7393c43b400d89ae94ab037586fc 最上面的管理层(canvas) using System…...

Django实现接口自动化平台(十四)测试用例模块Testcases序列化器及视图【持续更新中】
相关文章: Django实现接口自动化平台(十三)接口模块Interfaces序列化器及视图【持续更新中】_做测试的喵酱的博客-CSDN博客 本章是项目的一个分解,查看本章内容时,要结合整体项目代码来看: python django…...

如何高效实现文件传输:小文件采用零拷贝、大文件采用异步io+直接io
一般会如何实现文件传输? 服务器提供文件传输功能,需要将磁盘上的文件读取出来,通过网络协议发送到客户端。如果需要你自己编码实现这个文件传输功能,你会怎么实现呢? 通常,你会选择最直接的方法…...
Docker运行MySQL5.7
步骤如下: 1.获取镜像: docker pull mysql:5.7 2.创建挂载目录: mkdir /home/mydata/data mkdir /home/mydata/log mkdir /home/mydata/conf 3.先启动docker把配置文件拷贝出来: docker run -it --name temp mysql:5.7 /bi…...
-jar和 javaagent命令冲突吗?
当使用 -jar 命令运行 Java 应用程序时,Java 虚拟机 (JVM) 会忽略任何设置的 -javaagent 命令。这是因为 -jar 命令会覆盖其他命令行选项,包括 -javaagent。 这是因为 -jar 命令是用于运行打包为 JAR 文件的 Java 应用程序的快捷方式。它会忽略其他命令…...
LLC和MAC子层的应用
计算机局域网标准IEEE802 由于局域网只是一个计算机通信网,而且局域网不存在路由选择问题,因此它不需要网络层,而只有最低的两个层次。然而局域网的种类繁多,其媒体接入控制的方法也各不相同。 为了使局域网中的数据链路层不致过…...

【MySQL】之复合查询
【MySQL】之复合查询 基本查询多表查询笛卡尔积自连接子查询单行子查询多行子查询多列子查询在from子句中使用子查询 合并查询小练习 基本查询 查询工资高于500或岗位为MANAGER的雇员,同时还要满足他们的姓名首字母为大写的J按照部门号升序而雇员的工资降序排序使用…...

Vue系列第五篇:Vue2(Element UI) + Go(gin框架) + nginx开发登录页面及其校验登录功能
本篇使用Vue2开发前端,Go语言开发服务端,使用nginx代理部署实现登录页面及其校验功能。 目录 1.部署结构 2.Vue2前端 2.1代码结构 2.1源码 3.Go后台服务 3.2代码结构 3.2 源码 3.3单测效果 4.nginx 5.运行效果 6.问题总结 1.部署结构 2.Vue2…...

u盘里的数据丢失怎么恢复 u盘数据丢失怎么恢复
在使用U盘的时候不知道大家有没有经历过数据丢失或者U盘提示格式化的情况呢?U盘使用久了就会遇到各种各样的问题,而关于U盘数据丢失,大家又知道多少呢?当数据丢失了,我们应该怎样恢复数据?这个问题困扰了很…...
Mysql-约束
约束 概念:约束是作用于表中字段上的规则,用于限制存储在表中的数据。 目的:保证数据库中数据的正确、有效性和完整性。 分类: 约束描述关键字非空约束限制该字段的数据不能为nullNOT NULL唯一约束保证该字段的所有数据都是唯一…...
数据结构问答7
1. 图的定义和相关术语 答: 定义:图是由顶点集V和边集E组成,其中V为有限非空集。 相关术语:n个顶点,e条边,G=(V,E) ① 邻接点和端点:无向图中,若存在一条边(i, j),则称i,j为该边的端点,且它们互为邻接点;在有向图中,若存在一条边<i, j>,则称i,j分别为…...
[Spark] 大纲
1、Spark任务提交流程 2、SparkSQL执行流程 2.1 RBO,基于规则的优化 2.2 CBO,基于成本的优化 3、Spark性能调优 3.1 固定资源申请和动态资源分配 3.2 数据倾斜常见解决方法 3.3 小文件优化 4、Spark 3.0 4.1 动态分区裁剪(Dynamic Partition Pr…...

C++实现分布式网络通信框架RPC(3)--rpc调用端
目录 一、前言 二、UserServiceRpc_Stub 三、 CallMethod方法的重写 头文件 实现 四、rpc调用端的调用 实现 五、 google::protobuf::RpcController *controller 头文件 实现 六、总结 一、前言 在前边的文章中,我们已经大致实现了rpc服务端的各项功能代…...
深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法
深入浅出:JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中,随机数的生成看似简单,却隐藏着许多玄机。无论是生成密码、加密密钥,还是创建安全令牌,随机数的质量直接关系到系统的安全性。Jav…...

渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止
<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet: https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...

PL0语法,分析器实现!
简介 PL/0 是一种简单的编程语言,通常用于教学编译原理。它的语法结构清晰,功能包括常量定义、变量声明、过程(子程序)定义以及基本的控制结构(如条件语句和循环语句)。 PL/0 语法规范 PL/0 是一种教学用的小型编程语言,由 Niklaus Wirth 设计,用于展示编译原理的核…...
uniapp中使用aixos 报错
问题: 在uniapp中使用aixos,运行后报如下错误: AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...
C++八股 —— 单例模式
文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全(Thread Safety) 线程安全是指在多线程环境下,某个函数、类或代码片段能够被多个线程同时调用时,仍能保证数据的一致性和逻辑的正确性…...

用机器学习破解新能源领域的“弃风”难题
音乐发烧友深有体会,玩音乐的本质就是玩电网。火电声音偏暖,水电偏冷,风电偏空旷。至于太阳能发的电,则略显朦胧和单薄。 不知你是否有感觉,近两年家里的音响声音越来越冷,听起来越来越单薄? —…...

GitFlow 工作模式(详解)
今天再学项目的过程中遇到使用gitflow模式管理代码,因此进行学习并且发布关于gitflow的一些思考 Git与GitFlow模式 我们在写代码的时候通常会进行网上保存,无论是github还是gittee,都是一种基于git去保存代码的形式,这样保存代码…...

[免费]微信小程序问卷调查系统(SpringBoot后端+Vue管理端)【论文+源码+SQL脚本】
大家好,我是java1234_小锋老师,看到一个不错的微信小程序问卷调查系统(SpringBoot后端Vue管理端)【论文源码SQL脚本】,分享下哈。 项目视频演示 【免费】微信小程序问卷调查系统(SpringBoot后端Vue管理端) Java毕业设计_哔哩哔哩_bilibili 项…...
Vite中定义@软链接
在webpack中可以直接通过符号表示src路径,但是vite中默认不可以。 如何实现: vite中提供了resolve.alias:通过别名在指向一个具体的路径 在vite.config.js中 import { join } from pathexport default defineConfig({plugins: [vue()],//…...