Ejemplo n.º 1
0
	void from_array(T* v, int idx, int left, int right) {
		refreshr[idx] = false;
		if (left != right) {
			from_array(v, st_left(idx), left, st_middle(left,right));
			from_array(v, st_right(idx), st_middle(left,right)+1, right);
			tree[idx] = tree[st_left(idx)] + tree[st_right(idx)]; //##//
		} else
			tree[idx] = v[left];
	}
Ejemplo n.º 2
0
static PyObject *from_entry_data_list(MMDB_entry_data_list_s **entry_data_list)
{
    if (NULL == entry_data_list || NULL == *entry_data_list) {
        PyErr_SetString(
            MaxMindDB_error,
            "Error while looking up data. Your database may be corrupt or you have found a bug in libmaxminddb."
            );
        return NULL;
    }

    switch ((*entry_data_list)->entry_data.type) {
    case MMDB_DATA_TYPE_MAP:
        return from_map(entry_data_list);
    case MMDB_DATA_TYPE_ARRAY:
        return from_array(entry_data_list);
    case MMDB_DATA_TYPE_UTF8_STRING:
        return PyUnicode_FromStringAndSize(
                   (*entry_data_list)->entry_data.utf8_string,
                   (*entry_data_list)->entry_data.data_size
                   );
    case MMDB_DATA_TYPE_BYTES:
        return PyByteArray_FromStringAndSize(
                   (const char *)(*entry_data_list)->entry_data.bytes,
                   (Py_ssize_t)(*entry_data_list)->entry_data.data_size);
    case MMDB_DATA_TYPE_DOUBLE:
        return PyFloat_FromDouble((*entry_data_list)->entry_data.double_value);
    case MMDB_DATA_TYPE_FLOAT:
        return PyFloat_FromDouble((*entry_data_list)->entry_data.float_value);
    case MMDB_DATA_TYPE_UINT16:
        return PyLong_FromLong( (*entry_data_list)->entry_data.uint16);
    case MMDB_DATA_TYPE_UINT32:
        return PyLong_FromLong((*entry_data_list)->entry_data.uint32);
    case MMDB_DATA_TYPE_BOOLEAN:
        return PyBool_FromLong((*entry_data_list)->entry_data.boolean);
    case MMDB_DATA_TYPE_UINT64:
        return PyLong_FromUnsignedLongLong(
                   (*entry_data_list)->entry_data.uint64);
    case MMDB_DATA_TYPE_UINT128:
        return from_uint128(*entry_data_list);
    case MMDB_DATA_TYPE_INT32:
        return PyLong_FromLong((*entry_data_list)->entry_data.int32);
    default:
        PyErr_Format(MaxMindDB_error,
                     "Invalid data type arguments: %d",
                     (*entry_data_list)->entry_data.type);
        return NULL;
    }
    return NULL;
}
Ejemplo n.º 3
0
	inline void from_array(T array[]) { from_array(array, 0, 0, size-1); }