The use of common hash functions in Go language
Updated: March 20, 2015 11:13:02 Submission: hebedich
Hash table (also called hash table) is a data structure that is directly accessed based on the key value. That is, it accesses records by mapping key code values to a location in the table to speed up searches. The specific introduction is described in detail online, such as chatting hash table, so I will not be tiring here;
/** * Created with IntelliJ IDEA. * User: liaojie * Date: 12-9-8 * Time: 3:53 pm * To change this template use File | Settings | File Templates. */ package main import ( "crypto/md5" "crypto/sha1" "crypto/sha256" "crypto/sha512" "flag" //Command line option parser "fmt" "hash" "io" "os" ) var style = ("s", "sha256", "The Hasey function used: sha1, sha256") var filename = ("f", "", "File name that needs to be calculated") func main() { () var hs switch *style { case "md5": hs = () case "sha1": hs = () case "sha512": hs = () default: hs = () } if len(*filename) == 0 { filein, err := (()[len(())-1]) if err != nil { return } else { (hs, filein) } } else { filein, err := (*filename) if err != nil { return } else { (hs, filein) } } hashString := (nil) ("%x\n", hashString) }
The above is the entire content of this article, I hope you like it.
Related Articles
Nested slice array operation of go structure
This article mainly introduces the operation of nested slice arrays of go structures, which are of good reference value and hope it will be helpful to everyone. Let's take a look with the editor2021-04-04Golang's Fork/Join implementation code
Fork/Join is essentially a task decomposition. It decomposes a large task into several small tasks, and then further decomposes the small tasks until the minimum granularity, and then executes concurrently. Friends who are interested in Golang's Fork/Join implementation code will follow the editor to take a look.2023-01-01Deep understanding of WebSocket and WSS support in Golang
This article mainly introduces a deep understanding of the support of WebSocket and WSS in Golang, implements Golang to build WebSocket servers and clients, and uses self-signed certificates to implement the function of WSS. It has certain reference value. If you are interested, you can learn about it.2024-03-03Detailed explanation of the difference between new() and make() in Go language
This article mainly introduces the detailed explanation of the difference between new() and make() in Go language. This article explains the main characteristics of new and the main characteristics of make, and summarizes their differences. Friends who need it can refer to it.2014-10-10Go language fo loop and conditional judgment
This article mainly introduces the fo loop and conditional judgment in Go language. The for loop is a loop control structure that can execute a specified number of loops. We will judge the following article based on the conditions. Interested friends can refer to it.2021-10-10Go language practical implementation of a simple distributed system
Nowadays, many cloud-native systems and distributed systems, such as Kubernetes, are written in the Go language, because the Go language naturally supports asynchronous programming. This article will introduce how to write a simple distributed system in Go language. If you need it, please follow the editor to learn about it.2022-10-10Example of using grpc framework under golang
This article mainly introduces examples of using the GRPC framework under Golang. Friends in need can refer to it for reference. I hope it can be helpful. I wish you more progress and get better as soon as possible to get a salary increase.2022-04-04Methods for implementing sqrt in go language
This article mainly introduces the method of implementing sqrt in Go language, and analyzes the skills of implementing calculating square roots in Go language. Friends who need it can refer to it2015-03-03A detailed explanation of Golang’s timing task library gron’s design and principles
This article mainly introduces a detailed explanation of the design and principles of Golang timing task library gron. gron is a relatively compact and flexible timing task library that can perform timed and periodic tasks. Gron provides a simple, concurrent and secure interface2022-08-08Best practices for writing concise code in Go
Concise code is crucial to creating maintainable, readable and efficient software. Go is a language that emphasizes simplicity and neat code. In this article, we will discuss the best practices of writing concise Go code in combination with code examples. Friends who need it can refer to it.2023-09-09