array: remove temporary repeat2()
parent
cb31eeec55
commit
a94c1556ce
|
@ -132,7 +132,7 @@ fn (p mut Parser) is_sig() bool {
|
||||||
fn new_fn(mod string, is_public bool) Fn {
|
fn new_fn(mod string, is_public bool) Fn {
|
||||||
return Fn {
|
return Fn {
|
||||||
mod: mod
|
mod: mod
|
||||||
local_vars: [Var{}].repeat2(MaxLocalVars)
|
local_vars: [Var{}].repeat(MaxLocalVars)
|
||||||
is_public: is_public
|
is_public: is_public
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ fn build_keys() map[string]int {
|
||||||
|
|
||||||
// TODO remove once we have `enum Token { name('name') if('if') ... }`
|
// TODO remove once we have `enum Token { name('name') if('if') ... }`
|
||||||
fn build_token_str() []string {
|
fn build_token_str() []string {
|
||||||
mut s := [''].repeat2(NrTokens)
|
mut s := [''].repeat(NrTokens)
|
||||||
s[Token.keyword_beg] = ''
|
s[Token.keyword_beg] = ''
|
||||||
s[Token.keyword_end] = ''
|
s[Token.keyword_end] = ''
|
||||||
s[Token.eof] = 'eof'
|
s[Token.eof] = 'eof'
|
||||||
|
|
|
@ -86,21 +86,6 @@ pub fn (a array) repeat(nr_repeats int) array {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove
|
|
||||||
pub fn (a array) repeat2(nr_repeats int) array {
|
|
||||||
arr := array {
|
|
||||||
len: nr_repeats
|
|
||||||
cap: nr_repeats
|
|
||||||
element_size: a.element_size
|
|
||||||
data: malloc(nr_repeats * a.element_size)
|
|
||||||
}
|
|
||||||
val := a.data + 0 //nr_repeats * a.element_size
|
|
||||||
for i := 0; i < nr_repeats; i++ {
|
|
||||||
C.memcpy(arr.data + i * a.element_size, val, a.element_size)
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (a mut array) sort_with_compare(compare voidptr) {
|
pub fn (a mut array) sort_with_compare(compare voidptr) {
|
||||||
C.qsort(a.data, a.len, a.element_size, compare)
|
C.qsort(a.data, a.len, a.element_size, compare)
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ pub fn (c byte) is_capital() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b []byte) clone() []byte {
|
pub fn (b []byte) clone() []byte {
|
||||||
mut res := [byte(0)].repeat2(b.len)
|
mut res := [byte(0)].repeat(b.len)
|
||||||
for i := 0; i < b.len; i++ {
|
for i := 0; i < b.len; i++ {
|
||||||
res[i] = b[i]
|
res[i] = b[i]
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn array_repeat(val voidptr, nr_repeats, elm_size int) array {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (a array) repeat2(nr_repeats int) array {
|
pub fn (a array) repeat(nr_repeats int) array {
|
||||||
#return Array(a[0]).fill(nr_repeats)
|
#return Array(a[0]).fill(nr_repeats)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ pub fn (c byte) is_capital() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b []byte) clone() []byte {
|
pub fn (b []byte) clone() []byte {
|
||||||
mut res := [byte(0)].repeat2(b.len)
|
mut res := [byte(0)].repeat(b.len)
|
||||||
for i := 0; i < b.len; i++ {
|
for i := 0; i < b.len; i++ {
|
||||||
res[i] = b[i]
|
res[i] = b[i]
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ fn preorder_keys(node &mapnode, keys mut []string, key_i int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (m mut map) keys() []string {
|
pub fn (m mut map) keys() []string {
|
||||||
mut keys := [''].repeat2(m.size)
|
mut keys := [''].repeat(m.size)
|
||||||
if isnil(m.root) {
|
if isnil(m.root) {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,7 @@ pub fn (s string) index(p string) int {
|
||||||
if p.len > s.len {
|
if p.len > s.len {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
mut prefix := [0].repeat2(p.len)
|
mut prefix := [0].repeat(p.len)
|
||||||
mut j := 0
|
mut j := 0
|
||||||
for i := 1; i < p.len; i++ {
|
for i := 1; i < p.len; i++ {
|
||||||
for p[j] != p[i] && j > 0 {
|
for p[j] != p[i] && j > 0 {
|
||||||
|
@ -898,7 +898,7 @@ pub fn (s string) bytes() []byte {
|
||||||
if s.len == 0 {
|
if s.len == 0 {
|
||||||
return []byte
|
return []byte
|
||||||
}
|
}
|
||||||
mut buf := [byte(0)].repeat2(s.len)
|
mut buf := [byte(0)].repeat(s.len)
|
||||||
C.memcpy(buf.data, s.str, s.len)
|
C.memcpy(buf.data, s.str, s.len)
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ module strings
|
||||||
// use levenshtein distance algorithm to calculate
|
// use levenshtein distance algorithm to calculate
|
||||||
// the distance between between two strings (lower is closer)
|
// the distance between between two strings (lower is closer)
|
||||||
pub fn levenshtein_distance(a, b string) int {
|
pub fn levenshtein_distance(a, b string) int {
|
||||||
mut f := [0].repeat2(b.len+1)
|
mut f := [0].repeat(b.len+1)
|
||||||
for ca in a {
|
for ca in a {
|
||||||
mut j := 1
|
mut j := 1
|
||||||
mut fj1 := f[0]
|
mut fj1 := f[0]
|
||||||
|
@ -50,7 +50,7 @@ pub fn dice_coefficient(s1, s2 string) f32 {
|
||||||
mut intersection_size := 0
|
mut intersection_size := 0
|
||||||
for i := 0; i < b.len-1; i++ {
|
for i := 0; i < b.len-1; i++ {
|
||||||
bigram := b.substr(i, i+2)
|
bigram := b.substr(i, i+2)
|
||||||
count := if bigram in first_bigrams { first_bigrams[bigram] } else { 0 }
|
count := if bigram in first_bigrams { first_bigrams[bigram] } else { 0 }
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
first_bigrams[bigram] = count - 1
|
first_bigrams[bigram] = count - 1
|
||||||
intersection_size++
|
intersection_size++
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub fn repeat(c byte, n int) string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
//mut arr := malloc(n + 1)
|
//mut arr := malloc(n + 1)
|
||||||
mut arr := [byte(0)].repeat2(n + 1)
|
mut arr := [byte(0)].repeat(n + 1)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
arr[i] = c
|
arr[i] = c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue