Esempio n. 1
0
static ss_t *aux_resize_u(ss_t **s, const sbool_t cat, ss_t *src,
			  const size_t u_chars, int fill_char)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (!src)
		src = ss_void;
	const size_t at = (cat && *s) ? sd_get_size(*s) : 0,
		     char_size = sc_wc_to_utf8_size(fill_char),
		     current_u_chars = ss_len_u(src);
	RETURN_IF(u_chars == current_u_chars, ss_check(s)); /* same */
	const sbool_t aliasing = *s == src;
	const size_t srcs = sd_get_size(src);
	if (current_u_chars < u_chars) { /* fill */
		const size_t new_elems = u_chars - current_u_chars,
			     at_inc = srcs + new_elems * char_size;
		SS_OVERFLOW_CHECK(s, at, at_inc);
		const size_t out_size = at + at_inc;
		if (ss_reserve(s, out_size) >= out_size) {
			if (!cat && !aliasing) /* copy */
				ss_clear(s);
			if (!aliasing) {
				memcpy(get_str(*s) + at, get_str_r(src), srcs);
				inc_unicode_size(*s, current_u_chars);
				inc_size(*s, srcs);
			}
			size_t i = 0;
			for (; i < new_elems; i++)
				ss_cat_char(s, fill_char);
		}
	} else { /* cut */
		const char *ps = get_str_r(src);
		size_t actual_unicode_count = 0;
		const size_t head_size = sc_unicode_count_to_utf8_size(
						ps, 0, srcs, u_chars,
						&actual_unicode_count);
		SS_OVERFLOW_CHECK(s, at, head_size);
		const size_t out_size = at + head_size;
		S_ASSERT(u_chars == actual_unicode_count);
		if (!aliasing) { /* copy or cat */
			if (ss_reserve(s, out_size) >= out_size) {
				if (!cat && !aliasing) /* copy */
					ss_clear(s);
				memcpy(get_str(*s) + at, ps, head_size);
				inc_unicode_size(*s, actual_unicode_count);
				inc_size(*s, head_size);
			}
		} else { /* cut */
			set_size(*s, head_size);
			set_unicode_size(*s, actual_unicode_count);
		}
	}
	return *s;
}
Esempio n. 2
0
void buffer::append_from(network::input_stream* istream) {
    CPPA_REQUIRE(remaining() > 0);
    auto num_bytes = istream->read_some(wr_ptr(), remaining());
    if (num_bytes > 0) {
        inc_size(num_bytes);
    }
}
Esempio n. 3
0
void xyzsql_process_insert(insert_stmt *s ) {
    if ( s == NULL )
        s = dynamic_cast<insert_stmt *>(stmt_queue.front().second);

    auto t = catm.exist_relation(s->table_name)->cols;
    if (verify_validation(s->values, t) == false) 
        throw invalid_argument("Uncapatable values");
    
    auto table_info = catm.exist_relation(s->table_name);
    Record r(*(s->values), table_info->cols);

    for(auto x : *(r.table_info)) {
        if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
            string filename;
            indexIterator cursor;
            int asdf = IndexManager.selectNode(cursor, s->table_name + "/index_" + x->name + ".db", 
                    condition::EQUALTO, r.get_value(x).to_str(x->data_type));
            if (asdf == 0) throw invalid_argument("Unique Key already exists.");
        } 
    }

    int blockNum, offset;
    RecordManager.insertRecord(s->table_name, r, blockNum, offset);
    table_info->inc_size();

    for(auto x : *(r.table_info)) {
        if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
            IndexManager.insertNode(s->table_name + "/index_" + x->name + ".db", 
                    r.get_value(x->name).to_str(x->data_type) , blockNum, offset);
        } 
    }
}
Esempio n. 4
0
void buffer::write(size_t num_bytes, const void* data, buffer_write_policy wp) {
    if (wp == grow_if_needed) {
        acquire(num_bytes);
    }
    else if (num_bytes > remaining()) {
        throw std::ios_base::failure("final buffer size exceeded");
    }
    memcpy(wr_ptr(), data, num_bytes);
    inc_size(num_bytes);
}
Esempio n. 5
0
/* BEHAVIOR: aliasing is supported, e.g. append(&a, a) */
static ss_t *ss_cat_cn_raw(ss_t **s, const char *src, const size_t src_off,
			   const size_t src_size, const size_t src_usize)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (src && src_size > 0) {
		const size_t off = *s ? sd_get_size(*s) : 0;
		if (ss_grow(s, src_size)) {
			memmove(get_str(*s) + off, src + src_off, src_size);
			inc_size(*s, src_size);
			if (is_unicode_size_cached(*s)) {
				if (src_usize > 0)
					inc_unicode_size(*s, src_usize);
				else
					set_unicode_size_cached(*s, S_FALSE);
			}
		}
	}
	return ss_check(s);
}
Esempio n. 6
0
bool locked_add(struct hashtable *_t, int key, Packet_t *pkt) {
    struct locked_table *tab = (struct locked_table *) _t;
    int lock_ind = key & (tab->initial_cap - 1);

    bool trigger_resize = false;
    pthread_rwlock_wrlock (tab->locks + lock_ind);

    int bucket_ind = key & (tab->cap - 1);
    bool succ = s_add (tab->buckets + bucket_ind, key, pkt);

    if (tab->buckets[bucket_ind].size > RESIZE_THRESH)
        trigger_resize = true;

    pthread_rwlock_unlock (tab->locks + lock_ind);

    if (trigger_resize)
        inc_size(tab);

    return succ;
}