JNIEXPORT jlong JNICALL Java_io_realm_internal_TableQuery_nativeCount(
    JNIEnv* env, jobject, jlong nativeQueryPtr, jlong start, jlong end, jlong limit)
{
    Query* pQuery = Q(nativeQueryPtr);
    Table* pTable = Ref2Ptr(pQuery->get_table());
    if (!QUERY_VALID(env, pQuery) ||
        !ROW_INDEXES_VALID(env, pTable, start, end, limit))
        return 0;
    try {
        return pQuery->count(S(start), S(end), S(limit));
    } CATCH_STD()
    return 0;
}
예제 #2
0
TriStateTree::TriStateTree(const Query& query)
{
	m_state = Unknown;
	m_nodeCount = query.count();
	m_nodes = new Node[m_nodeCount];
	m_leafCount = 0;
	m_leafs = new Node*[m_nodeCount];
	Node** nodeStack = new Node*[m_nodeCount];
	int stackTop = -1;

	for (int element = 0; element < m_nodeCount; element++) {
		if (query.isElementSearch(element)) {
			/* search == leaf node, add to stack & add to list of leaf nodes */
			m_nodes[element].m_state = Unknown;
			m_nodes[element].m_operator = Search::NullOperator;
			m_nodes[element].m_parent = 0;
			m_nodes[element].m_leftChild = m_nodes[element].m_rightChild = 0;
			nodeStack[++stackTop] = &m_nodes[element];
			m_leafs[m_leafCount++] = &m_nodes[element];
		} else {
			/* operator == branch node, pop children off stack & add to stack */
			m_nodes[element].m_state = Unknown;
			m_nodes[element].m_operator = query.searchOperator(element);
			m_nodes[element].m_parent = 0;
			if (m_nodes[element].m_operator == Search::Not) {
				m_nodes[element].m_rightChild = 0;
			} else {
				m_nodes[element].m_rightChild = nodeStack[stackTop--];
				m_nodes[element].m_rightChild->m_parent = &m_nodes[element];
			}
			m_nodes[element].m_leftChild = nodeStack[stackTop--];
			m_nodes[element].m_leftChild->m_parent = &m_nodes[element];
			nodeStack[++stackTop] = &m_nodes[element];
		}
	}

	delete[] nodeStack;

	//stack should now be empty
	Q_ASSERT(stackTop == 0);
}