In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly analyzes the relevant knowledge points of how to understand the Go source code and Varint coding and Zigzag coding in ProtoBuf. The content is detailed and easy to understand, and the operation details are reasonable, which has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn more about "how to understand the Varint code and Zigzag coding in Go source code and ProtoBuf".
Recently, bloggers have been looking at the Go source code and found that the suffix array under index/suffixarray is also useful for Varint coding. They also found that ProtoBuf has a similar implementation. The principle is the same, and the specific coding method may be a little different.
Why use Varint coding and Zigzag coding
1. Let's first take a look at their respective Varint coding implementations
Go:
Func EncodeVarInt64 (v int) {var values [] int for v > = 128 {values = append (values, (v & (128-1)) | B) v > > = 7} values = append (values, v)}
ProtoBuf:
Func PutUvarint (buf [] byte, x uint64) int {I: = 0 for x > = 0x80 {buf [I] = byte (x) | 0x80 x > > = 7 icycles +} buf [I] = byte (x) return I + 1}
The implementation of the two is almost the same, the principle is every 7 bits as the significant bit, the highest bit as the flag bit, indicating that the data is not finished, need to loop read note: hexadecimal 0X80 = = decimal 128
two。 The most interesting part is the ZigZag coding implementation.
Go:
Func PutVarint (buf [] byte, x int64) int {ux: = uint64 (x) > 31 XOR is actually the same as 1111111111111111111111111111111111111111111111111111111111111111.
I = 1
I is positive, move the high position to the right to fill 0, and move to the left to move the low position to fill 0
I is negative, move the high position 1 to the right and the low position 0 to the left.
What is go golang is a compiled language that can compile the code into machine code, and the compiled binaries can be deployed directly to the target machine without additional dependencies, so golang outperforms other interpretive languages and can use goroutine in golang to achieve concurrency. It provides a very elegant goroutine scheduler system that can easily generate millions of goroutine.
This is the end of the introduction on "how to understand the Varint code and Zigzag code in Go source code and ProtoBuf". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.