OLD | NEW |
1 package util | 1 package util |
2 | 2 |
3 import "sort" | 3 import "sort" |
4 | 4 |
5 func In(s string, a []string) bool { | 5 func In(s string, a []string) bool { |
6 for _, x := range a { | 6 for _, x := range a { |
7 if x == s { | 7 if x == s { |
8 return true | 8 return true |
9 } | 9 } |
10 } | 10 } |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 // Since they are the same size we only need to check from one side, i.e
. | 40 // Since they are the same size we only need to check from one side, i.e
. |
41 // compare a's values to b's values. | 41 // compare a's values to b's values. |
42 for k, v := range a { | 42 for k, v := range a { |
43 if bv, ok := b[k]; !ok || bv != v { | 43 if bv, ok := b[k]; !ok || bv != v { |
44 return false | 44 return false |
45 } | 45 } |
46 } | 46 } |
47 return true | 47 return true |
48 } | 48 } |
| 49 |
| 50 // This is sad, but apparently there is no library function to get the absolute |
| 51 // value of an int. |
| 52 func AbsInt(v int) int { |
| 53 if v < 0 { |
| 54 return -v |
| 55 } |
| 56 return v |
| 57 } |
| 58 |
| 59 // Returns -1, 1 or 0 depending on the sign of v. |
| 60 func SignInt(v int) int { |
| 61 if v < 0 { |
| 62 return -1 |
| 63 } |
| 64 if v > 0 { |
| 65 return 1 |
| 66 } |
| 67 return 0 |
| 68 } |
OLD | NEW |