Exemple #1
0
def ensure_capacity_str(arr, new_size, n_chars):
    # new_size is right after write index
    new_arr = arr
    curr_len = len(arr)
    curr_num_chars = num_total_chars(arr)

    # TODO: corner case test
    #print("new alloc", new_size, curr_len, getitem_str_offset(arr, new_size-1), n_chars, curr_num_chars)
    if curr_len < new_size or getitem_str_offset(arr, new_size-1) + n_chars > curr_num_chars:
        new_len = 2 * curr_len
        new_num_chars = 2 * curr_num_chars
        new_arr = pre_alloc_string_array(new_len, new_num_chars)
        copy_str_arr_slice(new_arr, arr, new_size-1)

    return new_arr
Exemple #2
0
 def trim_arr_str(arr, size):
     # print("trim size", size, arr[size-1], getitem_str_offset(arr, size))
     new_arr = pre_alloc_string_array(size, np.int64(getitem_str_offset(arr, size)))
     copy_str_arr_slice(new_arr, arr, size)
     return new_arr