Pull to refresh
10
Karma
0
Rating
Aynur Zulkarnaev @aydu

User

  • Followers 4
  • Following

Algorithms in Go: Sliding Window Pattern

Hey sashagil!


Thank you for your comment and interesting observation!


While the precedence order that mentioned is correct to the vast majority of programming languages, it is not the case for Go:


There are five precedence levels for binary operators. Multiplication operators bind strongest, followed by addition operators, comparison operators, && (logical AND), and finally || (logical OR):

    5             *  /  %  <<  >>  &  &^
    4             +  -  |  ^
    3             ==  !=  <  <=  >  >=
    2             &&
    1             ||

The quote above is from Golang spec.


We can verify it in playground:


v := 1<<63 — 1
v1 := (1 << 63) — 1
fmt.Println(v == v1) // true

Возможное и невозможное

Уже не раз было отмечено - пренебрежимое старение это не фича, а баг эволюции. 

Очень интересное наблюдение, а где можно подробнее про это увидеть?

Go Quiz

Algorithms in Go: Dutch National Flag

Algorithms in Go: Dutch National Flag

Let me check if I got the idea.


Let's say we have [1, 2, 1, 0]
In the first pass, we count the number of occurrences for zeroes, ones and twos:


0:0, 1:2, 2:1


And in the second run, we restore the array. Did I get the idea?


If I understood you correctly, then the described algorithm does not work in-place, right?


EDIT: I noted that my post doesn't emphasize that the provided solution works in-place. Thanks for the remark, updated the article.

Prometheus in Action: from default counters to SLO-related queries

Thank you for the feedback!

Information

Rating
Does not participate
Registered
Activity