Rust vs Go:常用语法对比(五)

news2024/10/10 20:17:02
alt

题图来自 Rust vs Go 2023[1]


81. Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x . Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

按规则取整

package main

import (
 "fmt"
 "math"
)

func round(x float64) int {
 y := int(math.Floor(x + 0.5))
 return y
}

func main() {
 for _, x := range []float64{-1.1-0.9-0.5-0.10.0.10.50.91.1} {
  fmt.Printf("%5.1f %5d\n", x, round(x))
 }
}
 -1.1    -1
 -0.9    -1
 -0.5     0
 -0.1     0
  0.0     0
  0.1     0
  0.5     1
  0.9     1
  1.1     1

fn main() {
    let x : f64 = 2.71828;
    let y = x.round() as i64;
    
    println!("{} {}", x, y);
}

2.71828 3


82. Count substring occurrences

统计子字符串出现次数

package main

import (
 "fmt"
 "strings"
)

func main() {
 s := "Romaromamam"
 t := "mam"

 x := strings.Count(s, t)

 fmt.Println(x)
}

1


fn main() {
    let s = "lorem ipsum lorem ipsum lorem ipsum lorem ipsum";
    let t = "ipsum";

    let c = s.matches(t).count();

    println!("{} occurrences", c);
}

Disjoint matches: overlapping occurrences are not counted.

4 occurrences


83. Regex with character repetition

Declare regular expression r matching strings "http", "htttp", "httttp", etc.

正则表达式匹配重复字符

package main

import (
 "fmt"
 "regexp"
)

func main() {
 r := regexp.MustCompile("htt+p")

 for _, s := range []string{
  "hp",
  "htp",
  "http",
  "htttp",
  "httttp",
  "htttttp",
  "htttttp",
  "word htttp in a sentence",
 } {
  fmt.Println(s, "=>", r.MatchString(s))
 }
}
hp => false
htp => false
http => true
htttp => true
httttp => true
htttttp => true
htttttp => true
word htttp in a sentence => true

extern crate regex;
use regex::Regex;

fn main() {
    let r = Regex::new(r"htt+p").unwrap();
    
    assert!(r.is_match("http"));
    assert!(r.is_match("htttp"));
    assert!(r.is_match("httttp"));
}

84. Count bits set in integer binary representation

Count number c of 1s in the integer i in base 2.

E.g. i=6 → c=2

计算十进制整型的二进制表示中 1的个数

package main

import "fmt"

func PopCountUInt64(i uint64) (c int) {
 // bit population count, see
 // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
 i -= (i >> 1) & 0x5555555555555555
 i = (i>>2)&0x3333333333333333 + i&0x3333333333333333
 i += i >> 4
 i &= 0x0f0f0f0f0f0f0f0f
 i *= 0x0101010101010101
 return int(i >> 56)
}

func PopCountUInt32(i uint32) (n int) {
 // bit population count, see
 // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
 i -= (i >> 1) & 0x55555555
 i = (i>>2)&0x33333333 + i&0x33333333
 i += i >> 4
 i &= 0x0f0f0f0f
 i *= 0x01010101
 return int(i >> 24)
}

func main() {
 for i := uint64(0); i < 16; i++ {
  c := PopCountUInt64(i)
  fmt.Printf("%4d %04[1]b %d\n", i, c)
 }

 for i := uint32(0); i < 16; i++ {
  c := PopCountUInt32(i)
  fmt.Printf("%4d %04[1]b %d\n", i, c)
 }
}
   0 0000 0
   1 0001 1
   2 0010 1
   3 0011 2
   4 0100 1
   5 0101 2
   6 0110 2
   7 0111 3
   8 1000 1
   9 1001 2
  10 1010 2
  11 1011 3
  12 1100 2
  13 1101 3
  14 1110 3
  15 1111 4
   0 0000 0
   1 0001 1
   2 0010 1
   3 0011 2
   4 0100 1
   5 0101 2
   6 0110 2
   7 0111 3
   8 1000 1
   9 1001 2
  10 1010 2
  11 1011 3
  12 1100 2
  13 1101 3
  14 1110 3
  15 1111 4

This was useful only before go 1.9. See math/bits.OnesCount instead

or

package main

import (
 "fmt"
 "math/bits"
)

func main() {
 for i := uint(0); i < 16; i++ {
  c := bits.OnesCount(i)
  fmt.Printf("%4d %04[1]b %d\n", i, c)
 }
}

   0 0000 0
   1 0001 1
   2 0010 1
   3 0011 2
   4 0100 1
   5 0101 2
   6 0110 2
   7 0111 3
   8 1000 1
   9 1001 2
  10 1010 2
  11 1011 3
  12 1100 2
  13 1101 3
  14 1110 3
  15 1111 4

fn main() {
    println!("{}"6usize.count_ones())
}

2


85. Check if integer addition will overflow

检查两个整型相加是否溢出

package main

import (
 "fmt"
 "math"
)

func willAddOverflow(a, b int64) bool {
 return a > math.MaxInt64-b
}

func main() {

 fmt.Println(willAddOverflow(111111111111111112))

}

false


fn adding_will_overflow(x: usize, y: usize) -> bool {
    x.checked_add(y).is_none()
}

fn main() {
    {
        let (x, y) = (23456789012345);

        let overflow = adding_will_overflow(x, y);

        println!(
            "{} + {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (23456789019012345678);

        let overflow = adding_will_overflow(x, y);

        println!(
            "{} + {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (23456789012349012345678901);

        let overflow = adding_will_overflow(x, y);

        println!(
            "{} + {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (2345678901234567890123456789012345);

        let overflow = adding_will_overflow(x, y);

        println!(
            "{} + {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (123456789012345678909012345678901234567);

        let overflow = adding_will_overflow(x, y);

        println!(
            "{} + {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
}

2345678 + 9012345 doesn't overflow
2345678901 + 9012345678 doesn't overflow
2345678901234 + 9012345678901 doesn't overflow
23456789012345678 + 90123456789012345 doesn't overflow
12345678901234567890 + 9012345678901234567 overflows

86. Check if integer multiplication will overflow

检查整型相乘是否溢出

package main

import (
 "fmt"
)

func multiplyWillOverflow(x, y uint64) bool {
 if x <= 1 || y <= 1 {
  return false
 }
 d := x * y
 return d/y != x
}

func main() {
 {
  var x, y uint64 = 23456789
  if multiplyWillOverflow(x, y) {
   fmt.Println(x, "*", y, "overflows")
  } else {
   fmt.Println(x, "*", y, "doesn't overflow")
  }
 }
 {
  var x, y uint64 = 23456789012345
  if multiplyWillOverflow(x, y) {
   fmt.Println(x, "*", y, "overflows")
  } else {
   fmt.Println(x, "*", y, "doesn't overflow")
  }
 }
 {
  var x, y uint64 = 23456789019012345678
  if multiplyWillOverflow(x, y) {
   fmt.Println(x, "*", y, "overflows")
  } else {
   fmt.Println(x, "*", y, "doesn't overflow")
  }
 }
}

2345 * 6789 doesn't overflow
2345678 * 9012345 doesn'
t overflow
2345678901 * 9012345678 overflows

fn main() {
    {
        let (x, y) = (23456789);

        let overflow = multiply_will_overflow(x, y);

        println!(
            "{} * {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (23456789012345);

        let overflow = multiply_will_overflow(x, y);

        println!(
            "{} * {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
    {
        let (x, y) = (23456789019012345678);

        let overflow = multiply_will_overflow(x, y);

        println!(
            "{} * {} {}",
            x,
            y,
            if overflow {
                "overflows"
            } else {
                "doesn't overflow"
            }
        );
    }
}

fn multiply_will_overflow(x: i64, y: i64) -> bool {
    x.checked_mul(y).is_none()
}
2345 * 6789 doesn't overflow
2345678 * 9012345 doesn't overflow
2345678901 * 9012345678 overflows

87. Stop program

Exit immediately.
If some extra cleanup work is executed by the program runtime (not by the OS itself), describe it.

停止程序,立即退出。

package main

import "os"

func main() {

 os.Exit(1)

 print(2222)
}


fn main() {
    std::process::exit(1);
    println!("42");
}

88. Allocate 1M bytes

分配1M内存

package main

import "fmt"

func main() {
 buf := make([]byte1000000)

 for i, b := range buf {
  if b != 0 {
   fmt.Println("Found unexpected value", b, "at position", i)
  }
 }
 fmt.Println("Buffer was correctly initialized with zero values.")
}

Buffer was correctly initialized with zero values.


fn main() {
    let buf: Vec<u8> = Vec::with_capacity(1024 * 1024);
    println!("{:?}", buf.capacity());
}

1048576


89. Handle invalid argument

处理无效参数

package main

import "fmt"

// NewSquareMatrix creates a N-by-N matrix
func NewSquareMatrix(N int) ([][]float64, error) {
 if N < 0 {
  return nil, fmt.Errorf("Invalid size %d: order cannot be negative", N)
 }
 matrix := make([][]float64, N)
 for i := range matrix {
  matrix[i] = make([]float64, N)
 }
 return matrix, nil
}

func main() {
 N1 := 3
 matrix1, err1 := NewSquareMatrix(N1)
 if err1 == nil {
  fmt.Println(matrix1)
 } else {
  fmt.Println(err1)
 }

 N2 := -2
 matrix2, err2 := NewSquareMatrix(N2)
 if err2 == nil {
  fmt.Println(matrix2)
 } else {
  fmt.Println(err2)
 }
}

[[0 0 0] [0 0 0] [0 0 0]]
Invalid size -2: order cannot be negative

#[derive(Debug, PartialEq, Eq)]
enum CustomError { InvalidAnswer }

fn do_stuff(x: i32) -> Result<i32, CustomError> {
    if x != 42 {
%2

90. Read-only outside

外部只读

type Foo struct {
 x int
}

func (f *Foo) X() int {
 return f.x
}
x is private, because it is not capitalized.
(*Foo).X is a public getter (a read accessor).

struct Foo {
    x: usize
}

impl Foo {
    pub fn new(x: usize) -> Self {
        Foo { x }
    }

    pub fn x<'a>(&'a self) -> &'a usize {
        &self.x
    }
}

91. Load JSON file into struct

json转结构体

package main

import "fmt"
import "io/ioutil"
import "encoding/json"

func readJSONFile() error {
 var x Person

 buffer, err := ioutil.ReadFile(filename)
 if err != nil {
  return err
 }
 err = json.Unmarshal(buffer, &x)
 if err != nil {
  return err
 }

 fmt.Println(x)
 return nil
}

func main() {
 err := readJSONFile()
 if err != nil {
  panic(err)
 }
}

type Person struct {
 FirstName string
 Age       int
}

const filename = "/tmp/data.json"

func init() {
 err := ioutil.WriteFile(filename, []byte(`
  {
   "FirstName":"Napoléon",
   "Age": 51 
  }`
), 0644)
 if err != nil {
  panic(err)
 }
}

{Napoléon 51}

or

package main

import (
 "encoding/json"
 "fmt"
 "io/ioutil"
 "os"
)

func readJSONFile() error {
 var x Person

 r, err := os.Open(filename)
 if err != nil {
  return err
 }
 decoder := json.NewDecoder(r)
 err = decoder.Decode(&x)
 if err != nil {
  return err
 }

 fmt.Println(x)
 return nil
}

func main() {
 err := readJSONFile()
 if err != nil {
  panic(err)
 }
}

type Person struct {
 FirstName string
 Age       int
}

const filename = "/tmp/data.json"

func init() {
 err := ioutil.WriteFile(filename, []byte(`
  {
   "FirstName":"Napoléon",
   "Age": 51 
  }`
), 0644)
 if err != nil {
  panic(err)
 }
}

{Napoléon 51}


#[macro_use] extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
let x = ::serde_json::from_reader(File::open("data.json")?)?;

92. Save object into JSON file

将json对象写入文件

package main

import "fmt"
import "io/ioutil"
import "encoding/json"

func writeJSONFile() error {
 x := Person{
  FirstName: "Napoléon",
  Age:       51,
 }

 buffer, err := json.MarshalIndent(x, """  ")
 if err != nil {
  return err
 }
 return ioutil.WriteFile(filename, buffer, 0644)
}

func main() {
 err := writeJSONFile()
 if err != nil {
  panic(err)
 }
 fmt.Println("Done.")
}

type Person struct {
 FirstName string
 Age       int
}

const filename = "/tmp/data.json"

json.MarshalIndent is more human-readable than json.Marshal.

Done.


extern crate serde_json;
#[macro_use] extern crate serde_derive;

use std::fs::File;
::serde_json::to_writer(&File::create("data.json")?, &x)?

93. Pass a runnable procedure as parameter

Implement procedure control which receives one parameter f, and runs f.

以函数作为参数

package main

import "fmt"

func main() {
 control(greet)
}

func control(f func()) {
 fmt.Println("Before f")
 f()
 fmt.Println("After f")
}

func greet() {
 fmt.Println("Hello, developers")
}

Go supports first class functions, higher-order functions, user-defined function types, function literals, and closures.

Before f
Hello, developers
After f

fn control(f: impl Fn()) {
    f();
}

fn hello() {
    println!("Hello,");
}

fn main() {
    control(hello);
    control(|| { println!("Is there anybody in there?"); });
}

Hello,
Is there anybody in there?

94. Print type of variable

打印变量的类型

package main

import (
 "fmt"
 "os"
 "reflect"
)

func main() {
 var x interface{}

 x = "Hello"
 fmt.Println(reflect.TypeOf(x))

 x = 4
 fmt.Println(reflect.TypeOf(x))

 x = os.NewFile(0777"foobar.txt")
 fmt.Println(reflect.TypeOf(x))
}

string
int
*os.File

or

package main

import (
 "fmt"
 "os"
)

func main() {
 var x interface{}

 x = "Hello"
 fmt.Printf("%T", x)
 fmt.Println()

 x = 4
 fmt.Printf("%T", x)
 fmt.Println()

 x = os.NewFile(0777"foobar.txt")
 fmt.Printf("%T", x)
 fmt.Println()
}
string
int
*os.File

#![feature(core_intrinsics)]

fn type_of<T>(_: &T) -> String {
    format!("{}", std::intrinsics::type_name::<T>())
}

fn main() {
    let x: i32 = 1;
    println!("{}", type_of(&x));
}

i32


95. Get file size

获取文件的大小

package main

import (
 "fmt"
 "io/ioutil"
 "os"
)

func main() {
 err := printSize("file.txt")
 if err != nil {
  panic(err)
 }
}

func printSize(path string) error {
 info, err := os.Stat(path)
 if err != nil {
  return err
 }
 x := info.Size()

 fmt.Println(x)
 return nil
}

func init() {
 // The file will only contains the characters "Hello", no newlines.
 buffer := []byte("Hello")
 err := ioutil.WriteFile("file.txt", buffer, 0644)
 if err != nil {
  panic(err)
 }
}

5


use std::fs;

fn filesize(path: &str) -> Result<u64, std::io::Error> {
    let x = fs::metadata(path)?.len();
    Ok(x)
}

fn main() {
    let path = "/etc/hosts";
    let x = filesize(path);
    println!("{}: {:?} bytes", path, x.unwrap());
}

/etc/hosts: 150 bytes

or

use std::path::Path;

fn filesize(path: &std::path::Path) -> Result<u64, std::io::Error> {
    let x = path.metadata()?.len();
    Ok(x)
}

fn main() {
    let path = Path::new("/etc/hosts");
    let x = filesize(path);
    println!("{:?}: {:?} bytes", path, x.unwrap());
}

"/etc/hosts": 150 bytes


96. Check string prefix

Set boolean b to true if string s starts with prefix prefix, false otherwise.

检查两个字符串前缀是否一致

package main

import (
 "fmt"
 "strings"
)

func check(s, prefix string) {

 b := strings.HasPrefix(s, prefix)

 if b {
  fmt.Println(s, "starts with", prefix)
 } else {
  fmt.Println(s, "doesn't start with", prefix)
 }
}

func main() {
 check("bar""foo")
 check("foobar""foo")
}

bar doesn't start with foo
foobar starts with foo

fn main() {
    let s = "bananas";
    let prefix = "bana";

    let b = s.starts_with(prefix);

    println!("{:?}", b);
}

true


97. Check string suffix

Set boolean b to true if string s ends with string suffix, false otherwise.

检查字符串后缀

package main

import (
 "fmt"
 "strings"
)

func check(s, suffix string) {

 b := strings.HasSuffix(s, suffix)

 if b {
  fmt.Println(s, "ends with", suffix)
 } else {
  fmt.Println(s, "doesn't end with", suffix)
 }
}

func main() {
 check("foo""bar")
 check("foobar""bar")
}
foo doesn't end with bar
foobar ends with bar

fn main() {
    let s = "bananas";
    let suffix = "nas";

    let b = s.ends_with(suffix);

    println!("{:?}", b);
}

true


98. Epoch seconds to date object

Convert a timestamp ts (number of seconds in epoch-time) to a date with time d. E.g. 0 -> 1970-01-01 00:00:00

时间戳转日期

package main

import (
 "fmt"
 "time"
)

func main() {
 ts := int64(1451606400)
 d := time.Unix(ts, 0)

 fmt.Println(d)
}

2016-01-01 00:00:00 +0000 UTC


extern crate chrono;
use chrono::prelude::*;

fn main() {
    let ts = 1451606400;
    let d = NaiveDateTime::from_timestamp(ts, 0);
    println!("{}", d);
}

2016-01-01 00:00:00


99. Format date YYYY-MM-DD

Assign to string x the value of fields (year, month, day) of date d, in format YYYY-MM-DD.

时间格式转换

package main

import (
 "fmt"
 "time"
)

func main() {
 d := time.Now()
 x := d.Format("2006-01-02")
 fmt.Println(x)

 // The output may be "2009-11-10" because the Playground's clock is fixed in the past.
}

2009-11-10


extern crate chrono;

use chrono::prelude::*;

fn main() {
    println!("{}", Utc::today().format("%Y-%m-%d"))
}

2021-07-17


100. Sort by a comparator

Sort elements of array-like collection items, using a comparator c.

根据某个字段排序

package main

import "fmt"
import "sort"

type Item struct {
 label string
 p     int
 lang  string
}

// c returns true if x is "inferior to" y (in a custom way)
func c(x, y Item) bool {
 return x.p < y.p
}

type ItemCSorter []Item

func (s ItemCSorter) Len() int           { return len(s) }
func (s ItemCSorter) Less(i, j int) bool { return c(s[i], s[j]) }
func (s ItemCSorter) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

func sortItems(items []Item) {
 sorter := ItemCSorter(items)
 sort.Sort(sorter)
}

func main() {
 items := []Item{
  {"twelve"12"english"},
  {"six"6"english"},
  {"eleven"11"english"},
  {"zero"0"english"},
  {"two"2"english"},
 }
 fmt.Println("Unsorted: ", items)
 sortItems(items)
 fmt.Println("Sorted: ", items)
}

c has type func(Item, Item) bool.

Unsorted:  [{twelve 12 english} {six 6 english} {eleven 11 english} {zero 0 english} {two 2 english}]
Sorted:  [{zero 0 english} {two 2 english} {six 6 english} {eleven 11 english} {twelve 12 english}]

or

package main

import "fmt"
import "sort"

type Item struct {
 label string
 p     int
 lang  string
}

type ItemsSorter struct {
 items []Item
 c     func(x, y Item) bool
}

func (s ItemsSorter) Len() int           { return len(s.items) }
func (s ItemsSorter) Less(i, j int) bool { return s.c(s.items[i], s.items[j]) }
func (s ItemsSorter) Swap(i, j int)      { s.items[i], s.items[j] = s.items[j], s.items[i] }

func sortItems(items []Item, c func(x, y Item) bool) {
 sorter := ItemsSorter{
  items,
  c,
 }
 sort.Sort(sorter)
}

func main() {
 items := []Item{
  {"twelve"12"english"},
  {"six"6"english"},
  {"eleven"11"english"},
  {"zero"0"english"},
  {"two"2"english"},
 }
 fmt.Println("Unsorted: ", items)

 c := func(x, y Item) bool {
  return x.p < y.p
 }
 sortItems(items, c)

 fmt.Println("Sorted: ", items)
}

ItemsSorter contains c, which can be any comparator decided at runtime.

Unsorted:  [{twelve 12 english} {six 6 english} {eleven 11 english} {zero 0 english} {two 2 english}]
Sorted:  [{zero 0 english} {two 2 english} {six 6 english} {eleven 11 english} {twelve 12 english}]

or

package main

import "fmt"
import "sort"

type Item struct {
 label string
 p     int
 lang  string
}

// c returns true if x is "inferior to" y (in a custom way)
func c(x, y Item) bool {
 return x.p < y.p
}

func main() {
 items := []Item{
  {"twelve"12"english"},
  {"six"6"english"},
  {"eleven"11"english"},
  {"zero"0"english"},
  {"two"2"english"},
 }
 fmt.Println("Unsorted: ", items)
 
 sort.Slice(items, func(i, j int) bool {
  return c(items[i], items[j])
 })
 
 fmt.Println("Sorted: ", items)
}

Since Go 1.8, a single func parameter is sufficient to sort a slice.

Unsorted:  [{twelve 12 english} {six 6 english} {eleven 11 english} {zero 0 english} {two 2 english}]
Sorted:  [{zero 0 english} {two 2 english} {six 6 english} {eleven 11 english} {twelve 12 english}]

fn main() {
    let mut items = [17523];
    items.sort_by(i32::cmp);
    println!("{:?}", items);
}

[1, 2, 3, 5, 7]


参考资料

[1]

Rust vs Go 2023: https://arkiana.com/rust-vs-go/

本文由 mdnice 多平台发布

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/790159.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

垃圾回收标记阶段算法

1.标记阶段的目的 主要是在GC在前&#xff0c;判断出哪些是有用的对象&#xff0c;哪些是需要回收的对象&#xff0c;只有被标记为垃圾对象&#xff0c;GC才会对其进行垃圾回收。判断对象是否为垃圾对象的两种方式&#xff1a;引用计数算法和可达性分析算法。 2.引用计数算法…

MySQL基础(一)

目录 前言 一、概述 1.什么是数据库 2.数据库能干什么 3.为什么要用数据库&#xff0c;优势、特性 二、数据库类型 &#xff08;一&#xff09;、关系型数据库&#xff0c;RDBMS 1.概述 2.特点 3.代表产品 &#xff08;二&#xff09;、非关系型数据库&#xff0c;No…

性能测试常见故障和解决思路

目录 一、性能问题分析流程 二、内存溢出 &#xff08;一&#xff09;堆内存溢出 &#xff08;二&#xff09;永久代/方法区溢出 &#xff08;三&#xff09;栈内存溢出 &#xff08;四&#xff09;系统内存溢出 三、CPU过高 &#xff08;一&#xff09;us cpu过高 &a…

flink cdc环境搭建

1.下载flink https://archive.apache.org/dist/flink/flink-1.12.2/ 2.修改flink-conf.yaml #根据自己电脑核数修改&#xff0c;这里我设置为4&#xff0c;因为系统分配了4核 jobmanager.rpc.address: localhost #主机名根据自己设定 taskmanager.numberOfTaskSlots: 4 3.下载…

Databend 开源周报第 103 期

Databend 是一款现代云数仓。专为弹性和高效设计&#xff0c;为您的大规模分析需求保驾护航。自由且开源。即刻体验云服务&#xff1a;https://app.databend.cn 。 Whats On In Databend 探索 Databend 本周新进展&#xff0c;遇到更贴近你心意的 Databend 。 创建网络策略 …

机器学习深度学习——图像分类数据集

&#x1f468;‍&#x1f393;作者简介&#xff1a;一位即将上大四&#xff0c;正专攻机器学习的保研er &#x1f30c;上期文章&#xff1a;机器学习&&深度学习——softmax回归&#xff08;下&#xff09; &#x1f4da;订阅专栏&#xff1a;机器学习&&深度学习…

【腾讯云 Cloud Studio 实战训练营】沉浸式体验编写一个博客系统

文章目录 前言新建工作空间登录(注册)Cloud Studio 账号&#xff1a;进入 Cloud Studio 控制台&#xff1a;配置工作空间参数&#xff1a;确认并创建工作空间&#xff1a;项目搭建 配置nuxt 脚手架运行项目报错信息解决错误脚手架运行预览问题 开启博客代码配置layout首页配置 …

关于java中的内存回收机制

C中如果创建了一个对象&#xff0c;当不再使用的时候&#xff0c;需要手动调用delete方法来进行销毁。而Java提供了一套完整的垃圾回收机制&#xff08;gc&#xff09;。它会自动扫描内存中我们所创建过且不再使用的对象&#xff0c;进行自动销毁。但是gc并不完美&#xff0c;现…

7plus透明屏有哪些全新的使用体验?

7plus透明屏是指苹果公司推出的iPhone 7 Plus手机配备了透明屏幕的一种特殊版本。透明屏幕是一种新型的显示技术&#xff0c;可以使屏幕看起来透明&#xff0c;让用户感觉手机屏幕上的内容仿佛悬浮在空中一样。 透明屏幕的出现给用户带来了全新的使用体验。 首先&#xff0c;透…

对象存活判断

对象存活判断 在堆里存放着几乎所有的 Java 对象实例&#xff0c;在 GC 执行垃圾回收之前&#xff0c;首先需要区分出内存中哪些是存活对象&#xff0c;哪些是已经死亡的对象。只有被标记为己经死亡的对象&#xff0c;GC 才会在执行垃圾回收时&#xff0c;释放掉其所占用的内存…

微信小程序客服系统-对接消息推送-对接模板订阅消息-嵌入webview客服链接

想要给自己的小程序增加客服系统功能 小程序客服对接导自己的系统等需求&#xff0c;可以参照我开发的客服系统&#xff0c;实现私有化部署搭建对接的微信小程序 小程序消息推送对接 首先登录小程序后台在小程序后台>开发管理>开发设置>服务器域名部分&#xff0c;配置…

基于Java+SpringBoot+vue前后端分离学科竞赛管理系统设计实现

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

Linux中的库

一、库是什么 库是一种可执行代码的二进制形式&#xff0c;可以被操作系统载入内存执行。就是将源代码转化为二进制格式的源代码&#xff0c;相当于进行了加密&#xff0c;别人可以使用库&#xff0c;但是看不到库中的内容。 二、库的分类和优缺点 静态库&#xff1a;是在程…

Shell 排序法 - 改良的插入排序

说明 插入排序法由未排序的后半部前端取出一个值&#xff0c;插入已排序前半部的适当位置&#xff0c;概念简单但速度不快。 排序要加快的基本原则之一&#xff0c;是让后一次的排序进行时&#xff0c;尽量利用前一次排序后的结果&#xff0c;以加快排序的速度&#xff0c;Shel…

云安全攻防(二)之 云原生安全

云原生安全 什么是云原生安全&#xff1f;云原生安全包含两层含义&#xff1a;面向云原生环境的安全和具有云原生特征的安全 面向云原生环境的安全 面向云原生环境的安全的目标是防护云原生环境中的基础设施、编排系统和微服务系统的安全。这类安全机制不一定会具有云原生的…

git恢复删除的分支

1.查看被删除的分支 git remote prune --dry-run origin 被删除的分支是191 2.找到被删除分支的最后一次提交记录的commit SHA值 git reflog 最后一次提交的commit SHA值是3fa7532 3.恢复分支 git checkout -b xiaomeng 3fa7532 4.恢复成功后提交到远端&#xff0c;over&…

[大模型] LLaMA系列大模型调研与整理-llama/alpaca/lora(部分)

文章目录 LLaMA大模型及其衍生模型1. LLaMA2. stanford_alpaca3. ChatDoctor4. alpaca-lora5. Chinese-LLaMA-Alpaca6. BELLE 大模型综述 A Survey of Large Language Models 关键词&#xff1a;大模型&#xff0c;LLaMA&#xff0c;Alpaca&#xff0c;Lora&#xff0c;Belle&a…

git拉取提交代码进行身份验证-输入账号密码以及配置SSH公钥

git初次拉取代码或者提交代码时&#xff0c;需要进行身份验证。验证有两种方式&#xff1a;1、账号密码验证&#xff1b;2、SSH公钥验证。 本文章以gitee为例 账号密码验证 1.首先找到电脑本地项目文件夹&#xff0c;在地址栏中输入cmd回车&#xff0c;打开命令行窗口。 2.输入…

【Redis深度专题】「核心技术提升」探究Redis服务启动的过程机制的技术原理和流程分析的指南(集群功能分析)

探究Redis服务启动的过程机制的技术原理和流程分析的指南&#xff08;集群功能分析&#xff09; Redis集群的出现背景提升性能扩展性 Redis集群概述Redis Cluster特性分布Redis Cluster的Failover机制Redis集群节点宕机集群如何判断节点是否挂掉集群进入失败状态的必要条件 Fai…

git实战

git实战 第一章 快速入门 1.1 什么是git git是一个分布式的版本控制软件。 软件&#xff0c;类似于QQ、office、dota等安装到电脑上才能使用的工具。版本控制&#xff0c;类似于毕业论文、写文案、视频剪辑等&#xff0c;需要反复修改和保留原历史数据。分布式 - 文件夹拷贝…