From b86330c71f86b11ecd6938c7334aaaa9c3ac3db9 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 18 Nov 2011 21:10:17 -0800 Subject: [PATCH] add dict_iter_getCounts() --- xwords4/android/XWords4/jni/xwjni.c | 20 +++++++++++++++++++ .../org/eehouse/android/xw4/jni/XwJNI.java | 2 ++ 2 files changed, 22 insertions(+) diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 329f2eac1..fb46716d8 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -1400,6 +1400,26 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount return result; } +JNIEXPORT jintArray JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts +(JNIEnv* env, jclass C, jint closure ) +{ + jintArray result = NULL; + DictIterData* data = (DictIterData*)closure; + if ( NULL != data ) { + DictIter iter; + dict_initIter( &iter, data->dict, 0, MAX_COLS_DICT ); + + LengthsArray lens; + if ( 0 < dict_countWords( &iter, &lens ) ) { + XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) ); + result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens ); + (*env)->DeleteLocalRef( env, result ); + } + } + return result; +} + JNIEXPORT jobjectArray JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes ( JNIEnv* env, jclass C, jint closure ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index 2f18aec13..16bb6319c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -237,12 +237,14 @@ public class XwJNI { public static native int dict_getTileValue( int dictPtr, int tile ); // Dict iterator + public final static int MAX_COLS_DICT = 15; // from dictiter.h public static native int dict_iter_init( byte[] dict, String path, JNIUtils jniu ); public static native void dict_iter_setMinMax( int closure, int min, int max ); public static native void dict_iter_destroy( int closure ); public static native int dict_iter_wordCount( int closure ); + public static native int[] dict_iter_getCounts( int closure ); public static native String dict_iter_nthWord( int closure, int nn ); public static native String[] dict_iter_getPrefixes( int closure ); public static native int[] dict_iter_getIndices( int closure );