├── .gitignore ├── .idea ├── .name ├── codeStyles │ └── Project.xml ├── compiler.xml ├── dbnavigator.xml ├── deploymentTargetDropDown.xml ├── gradle.xml ├── intellij-javadocs-4.0.1.xml ├── jarRepositories.xml ├── misc.xml ├── render.experimental.xml └── vcs.xml ├── LICENSE ├── README.md ├── android-leveldb-master ├── .gitignore ├── .gitmodules ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── litl │ │ │ └── leveldb │ │ │ └── test │ │ │ └── DBTests.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── litl │ │ │ └── leveldb │ │ │ ├── Chunk.java │ │ │ ├── DB.java │ │ │ ├── DatabaseCorruptException.java │ │ │ ├── Iterator.java │ │ │ ├── LevelDBException.java │ │ │ ├── NativeObject.java │ │ │ ├── NotFoundException.java │ │ │ └── WriteBatch.java │ │ └── jni │ │ ├── Android.mk │ │ ├── Application.mk │ │ ├── Chunk.cc │ │ ├── Chunk.h │ │ ├── blocknames.cc │ │ ├── blocknames.h │ │ ├── com_litl_leveldb_Chunk.cc │ │ ├── com_litl_leveldb_DB.cc │ │ ├── com_litl_leveldb_Iterator.cc │ │ ├── com_litl_leveldb_WriteBatch.cc │ │ ├── debug_conf.h │ │ ├── leveldb │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── AUTHORS │ │ ├── CONTRIBUTING.md │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── NEWS │ │ ├── README.md │ │ ├── TODO │ │ ├── build_detect_platform │ │ ├── db │ │ │ ├── autocompact_test.cc │ │ │ ├── builder.cc │ │ │ ├── builder.h │ │ │ ├── c.cc │ │ │ ├── c_test.c │ │ │ ├── corruption_test.cc │ │ │ ├── db_bench.cc │ │ │ ├── db_impl.cc │ │ │ ├── db_impl.h │ │ │ ├── db_iter.cc │ │ │ ├── db_iter.h │ │ │ ├── db_test.cc │ │ │ ├── dbformat.cc │ │ │ ├── dbformat.h │ │ │ ├── dbformat_test.cc │ │ │ ├── dumpfile.cc │ │ │ ├── fault_injection_test.cc │ │ │ ├── filename.cc │ │ │ ├── filename.h │ │ │ ├── filename_test.cc │ │ │ ├── leveldbutil.cc │ │ │ ├── log_format.h │ │ │ ├── log_reader.cc │ │ │ ├── log_reader.h │ │ │ ├── log_test.cc │ │ │ ├── log_writer.cc │ │ │ ├── log_writer.h │ │ │ ├── memtable.cc │ │ │ ├── memtable.h │ │ │ ├── recovery_test.cc │ │ │ ├── repair.cc │ │ │ ├── skiplist.h │ │ │ ├── skiplist_test.cc │ │ │ ├── snappy_compressor.cc │ │ │ ├── snapshot.h │ │ │ ├── table_cache.cc │ │ │ ├── table_cache.h │ │ │ ├── version_edit.cc │ │ │ ├── version_edit.h │ │ │ ├── version_edit_test.cc │ │ │ ├── version_set.cc │ │ │ ├── version_set.h │ │ │ ├── version_set_test.cc │ │ │ ├── write_batch.cc │ │ │ ├── write_batch_internal.h │ │ │ ├── write_batch_test.cc │ │ │ ├── zlib_compressor.cc │ │ │ ├── zopfli_compressor.cc │ │ │ └── zstd_compressor.cc │ │ ├── doc │ │ │ ├── bench │ │ │ │ ├── db_bench_sqlite3.cc │ │ │ │ └── db_bench_tree_db.cc │ │ │ ├── benchmark.html │ │ │ ├── impl.md │ │ │ ├── index.md │ │ │ ├── log_format.md │ │ │ └── table_format.md │ │ ├── helpers │ │ │ └── memenv │ │ │ │ ├── memenv.cc │ │ │ │ ├── memenv.h │ │ │ │ └── memenv_test.cc │ │ ├── include │ │ │ └── leveldb │ │ │ │ ├── c.h │ │ │ │ ├── cache.h │ │ │ │ ├── comparator.h │ │ │ │ ├── compressor.h │ │ │ │ ├── db.h │ │ │ │ ├── decompress_allocator.h │ │ │ │ ├── dumpfile.h │ │ │ │ ├── env.h │ │ │ │ ├── filter_policy.h │ │ │ │ ├── iterator.h │ │ │ │ ├── options.h │ │ │ │ ├── slice.h │ │ │ │ ├── snappy_compressor.h │ │ │ │ ├── status.h │ │ │ │ ├── table.h │ │ │ │ ├── table_builder.h │ │ │ │ ├── write_batch.h │ │ │ │ ├── zlib_compressor.h │ │ │ │ ├── zopfli_compressor.h │ │ │ │ └── zstd_compressor.h │ │ ├── issues │ │ │ ├── issue178_test.cc │ │ │ └── issue200_test.cc │ │ ├── mcpe_sample_setup.cpp │ │ ├── port │ │ │ ├── README │ │ │ ├── atomic_pointer.h │ │ │ ├── port.h │ │ │ ├── port_example.h │ │ │ ├── port_posix.cc │ │ │ ├── port_posix.h │ │ │ ├── port_posix_sse.cc │ │ │ ├── port_win.cc │ │ │ ├── port_win.h │ │ │ ├── port_winrt.cc │ │ │ ├── port_winrt.h │ │ │ ├── port_wp8.cc │ │ │ ├── port_wp8.h │ │ │ ├── thread_annotations.h │ │ │ └── win │ │ │ │ └── stdint.h │ │ ├── table │ │ │ ├── block.cc │ │ │ ├── block.h │ │ │ ├── block_builder.cc │ │ │ ├── block_builder.h │ │ │ ├── filter_block.cc │ │ │ ├── filter_block.h │ │ │ ├── filter_block_test.cc │ │ │ ├── format.cc │ │ │ ├── format.h │ │ │ ├── iterator.cc │ │ │ ├── iterator_wrapper.h │ │ │ ├── merger.cc │ │ │ ├── merger.h │ │ │ ├── table.cc │ │ │ ├── table_builder.cc │ │ │ ├── table_test.cc │ │ │ ├── two_level_iterator.cc │ │ │ └── two_level_iterator.h │ │ └── util │ │ │ ├── Filepath.h │ │ │ ├── arena.cc │ │ │ ├── arena.h │ │ │ ├── arena_test.cc │ │ │ ├── bloom.cc │ │ │ ├── bloom_test.cc │ │ │ ├── cache.cc │ │ │ ├── cache_test.cc │ │ │ ├── coding.cc │ │ │ ├── coding.h │ │ │ ├── coding_test.cc │ │ │ ├── comparator.cc │ │ │ ├── crc32c.cc │ │ │ ├── crc32c.h │ │ │ ├── crc32c_test.cc │ │ │ ├── env.cc │ │ │ ├── env_boost.cc │ │ │ ├── env_posix.cc │ │ │ ├── env_posix_test.cc │ │ │ ├── env_posix_test_helper.h │ │ │ ├── env_test.cc │ │ │ ├── env_win.cc │ │ │ ├── env_winrt.cc │ │ │ ├── filter_policy.cc │ │ │ ├── hash.cc │ │ │ ├── hash.h │ │ │ ├── hash_test.cc │ │ │ ├── histogram.cc │ │ │ ├── histogram.h │ │ │ ├── logging.cc │ │ │ ├── logging.h │ │ │ ├── mutexlock.h │ │ │ ├── options.cc │ │ │ ├── posix_logger.h │ │ │ ├── random.h │ │ │ ├── status.cc │ │ │ ├── testharness.cc │ │ │ ├── testharness.h │ │ │ ├── testutil.cc │ │ │ ├── testutil.h │ │ │ ├── win_logger.cc │ │ │ └── win_logger.h │ │ ├── leveldbjni.cc │ │ ├── leveldbjni.h │ │ ├── mapkey.h │ │ ├── qstr.h │ │ ├── subchunk.cc │ │ └── subchunk.h └── settings.gradle ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tmsstudio │ │ └── mappaintingeditor │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tmsstudio │ │ │ └── mappaintingeditor │ │ │ ├── GridPicActivity.java │ │ │ ├── GridViewAdapter.java │ │ │ ├── HelpActivity.java │ │ │ ├── ImportPicActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MapItem.java │ │ │ ├── MapItemAdapter.java │ │ │ ├── Message │ │ │ └── Message.java │ │ │ ├── PicFactory │ │ │ ├── PicFactory.java │ │ │ └── PicTool.java │ │ │ ├── TransitionActivity.java │ │ │ ├── Util.java │ │ │ ├── Widget │ │ │ └── ExpandView.java │ │ │ ├── WorldType.java │ │ │ └── nbt │ │ │ ├── EditableNBT.java │ │ │ ├── Keys.java │ │ │ ├── convert │ │ │ ├── DataConverter.java │ │ │ ├── LevelDataConverter.java │ │ │ ├── NBTConstants.java │ │ │ ├── NBTInputStream.java │ │ │ └── NBTOutputStream.java │ │ │ └── tags │ │ │ ├── ByteArrayTag.java │ │ │ ├── ByteTag.java │ │ │ ├── CompoundTag.java │ │ │ ├── DoubleTag.java │ │ │ ├── EndTag.java │ │ │ ├── FloatTag.java │ │ │ ├── IntArrayTag.java │ │ │ ├── IntTag.java │ │ │ ├── ListTag.java │ │ │ ├── LongTag.java │ │ │ ├── ShortArrayTag.java │ │ │ ├── ShortTag.java │ │ │ ├── StringTag.java │ │ │ └── Tag.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_arrow_drop_down_black_24dp.xml │ │ ├── ic_arrow_drop_up_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ └── linearlayout_underline.xml │ │ ├── layout │ │ ├── activity11_main_select.xml │ │ ├── activity_expand_view.xml │ │ ├── activity_grid_pic.xml │ │ ├── activity_help.xml │ │ ├── activity_import_pic.xml │ │ ├── activity_main.xml │ │ ├── activity_map_item.xml │ │ ├── activity_transition.xml │ │ ├── menu_about.xml │ │ └── switch_item.xml │ │ ├── menu │ │ └── my_menu.xml │ │ ├── mipmap-hdpi │ │ ├── add_pic.png │ │ ├── ic_launcher.png │ │ └── world_icon.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tmsstudio │ └── mappaintingeditor │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Map Painting Editor -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/deploymentTargetDropDown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | -------------------------------------------------------------------------------- /.idea/render.experimental.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android-leveldb-master/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | obj 4 | libs 5 | local.properties 6 | .DS_Store 7 | .metadata 8 | .settings 9 | *~ 10 | 11 | 12 | ### Gradle template 13 | .gradle 14 | build/ 15 | 16 | # Ignore Gradle GUI config 17 | gradle-app.setting 18 | 19 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 20 | !gradle-wrapper.jar 21 | 22 | # Cache of project 23 | .gradletasknamecache 24 | 25 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 26 | # gradle/wrapper/gradle-wrapper.properties 27 | 28 | 29 | ### Android template 30 | # Built application files 31 | *.apk 32 | *.ap_ 33 | 34 | # Files for the ART/Dalvik VM 35 | *.dex 36 | 37 | # Java class files 38 | *.class 39 | 40 | # Generated files 41 | bin/ 42 | gen/ 43 | out/ 44 | 45 | # Gradle files 46 | .gradle/ 47 | 48 | # Local configuration file (sdk path, etc) 49 | 50 | # Proguard folder generated by Eclipse 51 | proguard/ 52 | 53 | # Log Files 54 | *.log 55 | 56 | # Android Studio Navigation editor temp files 57 | .navigation/ 58 | 59 | # Android Studio captures folder 60 | captures/ 61 | 62 | # Intellij 63 | *.iml 64 | .idea 65 | 66 | # Keystore files 67 | *.jks 68 | -------------------------------------------------------------------------------- /android-leveldb-master/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "library/src/main/jni/leveldb"] 2 | path = library/src/main/jni/leveldb 3 | url = https://github.com/Mojang/leveldb-mcpe.git 4 | -------------------------------------------------------------------------------- /android-leveldb-master/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributor guidelines 2 | 3 | TODO: guidelines 4 | 5 | -------------------------------------------------------------------------------- /android-leveldb-master/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Maintainer 2 | 3 | @litl 4 | 5 | 6 | # Forks 7 | 8 | @zhuowei 9 | 10 | > Added first support for the leveldb-mcpe fork. 11 | 12 | @protolambda 13 | 14 | > Updated android-leveldb to a less archaic, more modern android standard. 15 | 16 | 17 | # Contributors 18 | 19 | Feel free to add yourself if you contribute. -------------------------------------------------------------------------------- /android-leveldb-master/README.md: -------------------------------------------------------------------------------- 1 | # leveldb-android 2 | 3 | [leveldb](https://github.com/google/leveldb) for Android. 4 | 5 | Very simple bindings for using Leveldb from android. 6 | There is an ~~excellent~~ outdated project [leveldbjni](https://github.com/fusesource/leveldbjni) 7 | out there for using leveldb from Java but seems to be a bit too much. 8 | It has a bunch of dependencies, including a code generator, 9 | which might or might not work on Android. At least it is not trivial to get started. 10 | 11 | 12 | ## Dependencies 13 | 14 | The only external dependencies are Android SDK and NDK. 15 | 16 | 17 | ## Building. 18 | 19 | 1. Clone the project with git. (Including the leveldb git-submodule, change it to a different fork if you want) 20 | 2. Open it with Android Studio. (Easiest way, but building could also be done with just gradle) 21 | 3. Build the project with gradle (if it was not already started automatically) 22 | 4. Make the project (Build > Make project) 23 | 5. Library should be ready now! 24 | 25 | 26 | ## Installation 27 | 28 | After building, include the library module in your own project like this: 29 | 30 | `your-project/settings.gradle` 31 | 32 | include ':android-leveldb' 33 | project(':android-leveldb').projectDir = new File(rootProject.projectDir, '../android-leveldb/library') 34 | 35 | This assumes that you cloned the android-leveldb git repository in the parent-folder of your-project. 36 | 37 | And add the module as dependency in `your-project/app/build.gradle`: 38 | 39 | //include .so files in the build (native libraries) 40 | compile fileTree(include: ['*.jar', '*.so'], dir: 'libs') 41 | 42 | //include the android-leveldb library (see settings.gradle) 43 | compile project(':android-leveldb') 44 | 45 | 46 | 47 | ## License 48 | 49 | Please see the [LICENSE](LICENSE) file. 50 | 51 | 52 | ## Contributing 53 | 54 | Contributions are always welcome. 55 | 56 | See [CONTRIBUTORS.md](CONTRIBUTORS.md) for a list of contributors, forks, etc. 57 | 58 | ### TODO 59 | 60 | Contributor guidelines are not set up yet. 61 | -------------------------------------------------------------------------------- /android-leveldb-master/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | google() 5 | // maven { 6 | // url 'https://maven.google.com/' 7 | // name 'Google' 8 | // } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.2.1' 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | google() 19 | // maven { 20 | // url 'https://maven.google.com/' 21 | // name 'Google' 22 | // } 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /android-leveldb-master/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreatorMC/MapPaintingEditor/1145ec8fbf6fe03be9271ef4230ed59f18cbe890/android-leveldb-master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android-leveldb-master/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 08 22:03:20 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /android-leveldb-master/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android-leveldb-master/library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 31 5 | 6 | defaultConfig { 7 | minSdkVersion 16 8 | targetSdkVersion 31 9 | 10 | ndk { 11 | abiFilters 'armeabi-v7a','arm64-v8a' 12 | } 13 | } 14 | 15 | buildTypes { 16 | debug { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | externalNativeBuild { 27 | ndkBuild { 28 | path "src/main/jni/Android.mk" 29 | } 30 | } 31 | 32 | } 33 | 34 | dependencies { 35 | implementation fileTree(include: ['*.jar', '*.so'], dir: 'libs') 36 | testImplementation 'junit:junit:4.13.2' 37 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in *android*/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Keep LevelDB classes, native methods may not be obfuscated! 20 | -keep public class com.litl.leveldb.** { 21 | public private protected *; 22 | } 23 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/Chunk.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | import java.io.File; 4 | import java.nio.ByteBuffer; 5 | 6 | public class Chunk extends NativeObject { 7 | 8 | public Chunk(DB db, int x, int z, int dim) { 9 | super(); 10 | mPtr = nativeOpen(db.getPtr(), x, z, dim); 11 | } 12 | 13 | public int getBlock(int x, int y, int z) { 14 | return nativeGetBlock(mPtr, x, y, z); 15 | } 16 | 17 | public void close() { 18 | closeNativeObject(mPtr); 19 | } 20 | 21 | @Override 22 | protected void closeNativeObject(long ptr) { 23 | nativeClose(ptr); 24 | } 25 | 26 | private static native long nativeOpen(long dbptr, int x, int z, int dim); 27 | 28 | private static native int nativeGetBlock(long ckptr, int x, int y, int z); 29 | 30 | private static native void nativeClose(long ckPtr); 31 | 32 | { 33 | System.loadLibrary("leveldbjni"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/DatabaseCorruptException.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | public class DatabaseCorruptException extends LevelDBException { 4 | private static final long serialVersionUID = -2110293580518875321L; 5 | 6 | public DatabaseCorruptException() { 7 | } 8 | 9 | public DatabaseCorruptException(String error) { 10 | super(error); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/Iterator.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | public class Iterator extends NativeObject { 4 | Iterator(long iterPtr) { 5 | super(iterPtr); 6 | } 7 | 8 | @Override 9 | protected void closeNativeObject(long ptr) { 10 | nativeDestroy(ptr); 11 | } 12 | 13 | public void seekToFirst() { 14 | assertOpen("Iterator is closed"); 15 | nativeSeekToFirst(mPtr); 16 | } 17 | 18 | public void seekToLast() { 19 | assertOpen("Iterator is closed"); 20 | nativeSeekToLast(mPtr); 21 | } 22 | 23 | public void seek(byte[] target) { 24 | assertOpen("Iterator is closed"); 25 | if (target == null) { 26 | throw new IllegalArgumentException(); 27 | } 28 | nativeSeek(mPtr, target); 29 | } 30 | 31 | public boolean isValid() { 32 | assertOpen("Iterator is closed"); 33 | return nativeValid(mPtr); 34 | } 35 | 36 | public void next() { 37 | assertOpen("Iterator is closed"); 38 | nativeNext(mPtr); 39 | } 40 | 41 | public void prev() { 42 | assertOpen("Iterator is closed"); 43 | nativePrev(mPtr); 44 | } 45 | 46 | public byte[] getKey() { 47 | assertOpen("Iterator is closed"); 48 | return nativeKey(mPtr); 49 | } 50 | 51 | public byte[] getValue() { 52 | assertOpen("Iterator is closed"); 53 | return nativeValue(mPtr); 54 | } 55 | 56 | private static native void nativeDestroy(long ptr); 57 | 58 | private static native void nativeSeekToFirst(long ptr); 59 | 60 | private static native void nativeSeekToLast(long ptr); 61 | 62 | private static native void nativeSeek(long ptr, byte[] key); 63 | 64 | private static native boolean nativeValid(long ptr); 65 | 66 | private static native void nativeNext(long ptr); 67 | 68 | private static native void nativePrev(long ptr); 69 | 70 | private static native byte[] nativeKey(long dbPtr); 71 | 72 | private static native byte[] nativeValue(long dbPtr); 73 | } 74 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/LevelDBException.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | public class LevelDBException extends RuntimeException { 4 | private static final long serialVersionUID = 2903013251786326801L; 5 | 6 | public LevelDBException() { 7 | } 8 | 9 | public LevelDBException(String error) { 10 | super(error); 11 | } 12 | 13 | public LevelDBException(String error, Throwable cause) { 14 | super(error, cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/NativeObject.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | import java.io.Closeable; 4 | 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | 8 | abstract class NativeObject implements Closeable { 9 | private static final String TAG = NativeObject.class.getSimpleName(); 10 | protected long mPtr; 11 | private int mRefCount = 0; 12 | 13 | protected NativeObject() { 14 | // The Java wrapper counts as one reference, will 15 | // be released when closed 16 | ref(); 17 | } 18 | 19 | protected NativeObject(long ptr) { 20 | this(); 21 | 22 | if (ptr == 0) { 23 | throw new OutOfMemoryError("Failed to allocate native object"); 24 | } 25 | 26 | mPtr = ptr; 27 | } 28 | 29 | synchronized protected long getPtr() { 30 | return mPtr; 31 | } 32 | 33 | synchronized public boolean isClosed(){ 34 | return getPtr() == 0; 35 | } 36 | 37 | protected void assertOpen(String message) { 38 | if (getPtr() == 0) { 39 | throw new IllegalStateException(message); 40 | } 41 | } 42 | 43 | synchronized void ref() { 44 | mRefCount++; 45 | } 46 | 47 | synchronized void unref() { 48 | if (mRefCount <= 0) { 49 | throw new IllegalStateException("Reference count is already 0"); 50 | } 51 | 52 | mRefCount--; 53 | 54 | if (mRefCount == 0) { 55 | closeNativeObject(mPtr); 56 | mPtr = 0; 57 | } 58 | } 59 | 60 | protected abstract void closeNativeObject(long ptr); 61 | 62 | @Override 63 | public synchronized void close() { 64 | if (mPtr != 0) { 65 | unref(); 66 | } 67 | } 68 | 69 | @Override 70 | protected void finalize() throws Throwable { 71 | if (mPtr != 0) { 72 | Class clazz = getClass(); 73 | String name = clazz.getSimpleName(); 74 | while (TextUtils.isEmpty(name)) { 75 | clazz = clazz.getSuperclass(); 76 | name = clazz.getSimpleName(); 77 | } 78 | 79 | Log.w(TAG, "NativeObject " + name + " refcount: " + mRefCount 80 | + " id: " + System.identityHashCode(this) 81 | + " was finalized before native resource was closed, did you forget to call close()?"); 82 | } 83 | 84 | super.finalize(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | public class NotFoundException extends LevelDBException { 4 | private static final long serialVersionUID = 6207999645579440001L; 5 | 6 | public NotFoundException() { 7 | } 8 | 9 | public NotFoundException(String error) { 10 | super(error); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/java/com/litl/leveldb/WriteBatch.java: -------------------------------------------------------------------------------- 1 | package com.litl.leveldb; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class WriteBatch extends NativeObject { 6 | public WriteBatch() { 7 | super(nativeCreate()); 8 | } 9 | 10 | @Override 11 | protected void closeNativeObject(long ptr) { 12 | nativeDestroy(ptr); 13 | } 14 | 15 | public void delete(ByteBuffer key) { 16 | assertOpen("WriteBatch is closed"); 17 | if (key == null) { 18 | throw new NullPointerException("key"); 19 | } 20 | 21 | nativeDelete(mPtr, key); 22 | } 23 | 24 | public void put(ByteBuffer key, ByteBuffer value) { 25 | assertOpen("WriteBatch is closed"); 26 | if (key == null) { 27 | throw new NullPointerException("key"); 28 | } 29 | if (value == null) { 30 | throw new NullPointerException("value"); 31 | } 32 | 33 | nativePut(mPtr, key, value); 34 | } 35 | 36 | public void clear() { 37 | assertOpen("WriteBatch is closed"); 38 | nativeClear(mPtr); 39 | } 40 | 41 | private static native long nativeCreate(); 42 | 43 | private static native void nativeDestroy(long ptr); 44 | 45 | private static native void nativeDelete(long ptr, ByteBuffer key); 46 | 47 | private static native void nativePut(long ptr, ByteBuffer key, ByteBuffer val); 48 | 49 | private static native void nativeClear(long ptr); 50 | } 51 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := leveldbjni 5 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/leveldb/include $(LOCAL_PATH)/leveldb/include/leveldb 6 | LOCAL_CPP_EXTENSION := .cc 7 | LOCAL_CFLAGS := -DLEVELDB_PLATFORM_ANDROID -std=gnu++11 -DDLLX= 8 | LOCAL_SRC_FILES := com_litl_leveldb_DB.cc com_litl_leveldb_Iterator.cc\ 9 | com_litl_leveldb_WriteBatch.cc leveldbjni.cc com_litl_leveldb_Chunk.cc\ 10 | subchunk.cc Chunk.cc blocknames.cc 11 | LOCAL_STATIC_LIBRARIES += leveldb 12 | LOCAL_LDLIBS += -llog -ldl -lz 13 | 14 | include $(BUILD_SHARED_LIBRARY) 15 | 16 | 17 | 18 | include $(CLEAR_VARS) 19 | LOCAL_MODULE := leveldb 20 | LOCAL_CFLAGS := -O3 -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX -DNDEBUG -std=gnu++11 -DDLLX= 21 | LOCAL_CPP_EXTENSION := .cc 22 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/leveldb $(LOCAL_PATH)/leveldb/include $(LOCAL_PATH)/leveldb/include/leveldb 23 | LOCAL_SRC_FILES := leveldb/db/builder.cc leveldb/db/c.cc leveldb/db/dbformat.cc leveldb/db/db_impl.cc leveldb/db/db_iter.cc leveldb/db/dumpfile.cc leveldb/db/filename.cc leveldb/db/log_reader.cc leveldb/db/log_writer.cc leveldb/db/memtable.cc leveldb/db/repair.cc leveldb/db/table_cache.cc leveldb/db/version_edit.cc leveldb/db/version_set.cc leveldb/db/write_batch.cc leveldb/db/zlib_compressor.cc leveldb/table/block_builder.cc leveldb/table/block.cc leveldb/table/filter_block.cc leveldb/table/format.cc leveldb/table/iterator.cc leveldb/table/merger.cc leveldb/table/table_builder.cc leveldb/table/table.cc leveldb/table/two_level_iterator.cc leveldb/util/arena.cc leveldb/util/bloom.cc leveldb/util/cache.cc leveldb/util/coding.cc leveldb/util/comparator.cc leveldb/util/crc32c.cc leveldb/util/env_boost.cc leveldb/util/env.cc leveldb/util/env_posix.cc leveldb/util/env_win.cc leveldb/util/filter_policy.cc leveldb/util/hash.cc leveldb/util/histogram.cc leveldb/util/logging.cc leveldb/util/options.cc leveldb/util/status.cc leveldb/util/win_logger.cc leveldb/port/port_posix.cc leveldb/port/port_posix_sse.cc 24 | 25 | include $(BUILD_STATIC_LIBRARY) -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM=android-16 2 | APP_ABI := armeabi-v7a x86 x86_64 arm64-v8a 3 | APP_STL := c++_static 4 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/Chunk.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/3/23. 3 | // 4 | 5 | 6 | #include 7 | #include "Chunk.h" 8 | #include "mapkey.h" 9 | #include "qstr.h" 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef LOG_CHUNK_LOADSAVE 15 | #define LOGE_LS(x, ...) LOGE(CAT("Chunk: ", x), ##__VA_ARGS__); 16 | #else 17 | #define LOGE_LS(x, ...) 18 | #endif 19 | 20 | #ifdef LOG_CHUNK_OPERATION 21 | #define LOGE_OP(x, ...) LOGE(CAT("Chunk: ", x), ##__VA_ARGS__); 22 | #else 23 | #define LOGE_OP(x, ...) 24 | #endif 25 | 26 | //Init constants. 27 | 28 | const int32_t Chunk::msk[] = {0b1, 0b11, 0b111, 0b1111, 0b11111, 0b111111, 0b1111111, 29 | 0b11111111, 30 | 0b111111111, 0b1111111111, 0b11111111111, 31 | 0b111111111111, 32 | 0b1111111111111, 0b11111111111111, 0b11111111111111}; 33 | 34 | const char Chunk::pattern_name[] = {0x0a, 0x00, 0x00, 0x08, 0x04, 0x00, 'n', 'a', 'm', 35 | 'e'}; 36 | 37 | const char Chunk::pattern_val[] = {0x02, 0x03, 0x00, 'v', 'a', 'l'}; 38 | 39 | Chunk::Chunk(leveldb::DB *db, mapkey_t key) 40 | : key(key) { 41 | std::string str; 42 | memset(subchunks, 0, sizeof(subchunks)); 43 | for (int i = 0; i < 16; i++) { 44 | loadSubChunk(db, i); 45 | } 46 | } 47 | 48 | void Chunk::loadSubChunk(leveldb::DB *db, unsigned char which) { 49 | LDBKEY_SUBCHUNK(this->key, which) 50 | leveldb::Slice slice(key, 0 == this->key.dimension ? 10 : 14); 51 | std::string val; 52 | leveldb::ReadOptions readOptions; 53 | readOptions.decompress_allocator = new leveldb::DecompressAllocator; 54 | bool hit = db->Get(readOptions, slice, &val).ok(); 55 | if (hit) {//Found, detect version. 56 | switch (val[0]) { 57 | case 0://Aligned subchunk. 58 | case 2://All 59 | case 3://The 60 | case 4://Same 61 | case 5://Really 62 | case 6://Wierd 63 | case 7://Ahhh 64 | break; 65 | case 8://Current paletted format 66 | subchunks[which] = new SubChunk(val, true); 67 | break; 68 | case 1: //Previous paletted version 69 | subchunks[which] = new SubChunk(val, false); 70 | break; 71 | default: 72 | //Unsupported format. 73 | break; 74 | } 75 | } 76 | } 77 | 78 | uint16_t Chunk::getBlock(unsigned char x, unsigned char y, unsigned char z) { 79 | unsigned char sub = y >> 4; 80 | if (subchunks[sub] == nullptr)return 0; 81 | return subchunks[sub]->getBlock(x, static_cast(y & 0xf), z); 82 | } 83 | 84 | Chunk::~Chunk() { 85 | for (int i = 0; i < 16; i++) { 86 | delete subchunks[i]; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/Chunk.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/3/23. 3 | // 4 | 5 | #ifndef CONVARTER_CHUNK_H 6 | #define CONVARTER_CHUNK_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "mapkey.h" 13 | #include "debug_conf.h" 14 | #include "qstr.h" 15 | 16 | class Chunk { 17 | private: 18 | 19 | //Constants. 20 | 21 | static const int32_t msk[]; 22 | 23 | static const char pattern_name[]; 24 | 25 | static const char pattern_val[]; 26 | 27 | //Member vars. 28 | 29 | mapkey_t key; 30 | 31 | SubChunk *subchunks[16]; 32 | 33 | void loadSubChunk(leveldb::DB *db, unsigned char which); 34 | 35 | public: 36 | 37 | Chunk(leveldb::DB *db, mapkey_t key); 38 | 39 | ~Chunk(); 40 | 41 | uint16_t getBlock(unsigned char x, unsigned char y, unsigned char z); 42 | }; 43 | 44 | #endif //CONVARTER_CHUNK_H 45 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/blocknames.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/3/29. 3 | // 4 | 5 | #ifndef CONVARTER_BLOCKNAMES_H 6 | #define CONVARTER_BLOCKNAMES_H 7 | 8 | #include "qstr.h" 9 | 10 | class BlockNames { 11 | public: 12 | static char names[256][32]; 13 | 14 | static unsigned char resolve(qstr name); 15 | }; 16 | 17 | #endif //CONVARTER_BLOCKNAMES_H 18 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/com_litl_leveldb_Chunk.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "leveldbjni.h" 10 | #include "Chunk.h" 11 | 12 | static jlong nativeOpen(JNIEnv *env, jclass clazz, jlong dbptr, jint x, jint z, jint dim) { 13 | leveldb::DB *db = reinterpret_cast(dbptr); 14 | Chunk *chunk = new Chunk(db, LDBKEY_STRUCT(x, z, dim)); 15 | return reinterpret_cast(chunk); 16 | } 17 | 18 | static jint nativeGetBlock(JNIEnv *env, jclass clazz, jlong ckptr, jint x, jint y, jint z) { 19 | Chunk *chunk = reinterpret_cast(ckptr); 20 | return chunk->getBlock(static_cast(x), static_cast(y), 21 | static_cast(z)); 22 | } 23 | 24 | static void nativeClose(JNIEnv *env, jclass clazz, jlong ckptr) { 25 | Chunk *chunk = reinterpret_cast(ckptr); 26 | delete chunk; 27 | } 28 | 29 | static JNINativeMethod sMethods[] = 30 | { 31 | {"nativeOpen", "(JIII)J", (void *) nativeOpen}, 32 | {"nativeGetBlock", "(JIII)I", (void *) nativeGetBlock}, 33 | {"nativeClose", "(J)V", (void *) nativeClose} 34 | }; 35 | 36 | int 37 | register_com_litl_leveldb_Chunk(JNIEnv *env) { 38 | jclass clazz = env->FindClass("com/litl/leveldb/Chunk"); 39 | if (!clazz) { 40 | LOGE("Can't find class com.litl.leveldb.Chunk"); 41 | return 0; 42 | } 43 | 44 | return env->RegisterNatives(clazz, sMethods, NELEM(sMethods)); 45 | } 46 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/debug_conf.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/4/12. 3 | // 4 | 5 | #ifndef CONVARTER_DEBUG_CONF_H 6 | #define CONVARTER_DEBUG_CONF_H 7 | 8 | //Chunk 9 | //#define LOG_CHUNK_OPERATION 10 | #define LOG_CHUNK_LOADSAVE 11 | 12 | //World 13 | //#define LOG_SAVDB_OPERATION 14 | #define LOG_SAVDB_LOADSAVE 15 | #define LOG_SAVDB_LRU 16 | 17 | #ifdef LOG_CHUNK_OPERATION 18 | #ifndef LOG_CHUNK_LOADSAVE 19 | #define LOG_CHUNK_LOADSAVE 20 | #endif 21 | #endif 22 | 23 | #ifdef LOG_SAVDB_OPERATION 24 | #ifndef LOG_SAVDB_LOADSAVE 25 | #define LOG_SAVDB_LOADSAVE 26 | #endif 27 | #ifndef LOG_SAVDB_LRU 28 | #define LOG_SAVDB_LRU 29 | #endif 30 | #endif 31 | 32 | #define CAT(x, y) x y 33 | 34 | #endif //CONVARTER_DEBUG_CONF_H 35 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | *.a 3 | *.o 4 | *.dylib* 5 | *.so 6 | *.so.* 7 | *_test 8 | db_bench 9 | leveldbutil 10 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - clang 4 | - gcc 5 | os: 6 | - linux 7 | - osx 8 | sudo: false 9 | before_install: 10 | - echo $LANG 11 | - echo $LC_ALL 12 | script: 13 | - make -j 4 check 14 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your code patches! However, before we can take them, we 4 | have to jump a couple of legal hurdles. 5 | 6 | ## Contributor License Agreements 7 | 8 | Please fill out either the individual or corporate Contributor License 9 | Agreement as appropriate. 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. 18 | 19 | ## Submitting a Patch 20 | 21 | 1. Sign the contributors license agreement above. 22 | 2. Decide which code you want to submit. A submission should be a set of changes 23 | that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues). 24 | Please don't mix more than one logical change per submission, because it makes 25 | the history hard to follow. If you want to make a change 26 | (e.g. add a sample or feature) that doesn't have a corresponding issue in the 27 | issue tracker, please create one. 28 | 3. **Submitting**: When you are ready to submit, send us a Pull Request. Be 29 | sure to include the issue number you fixed and the name you used to sign 30 | the CLA. 31 | 32 | ## Writing Code ## 33 | 34 | If your contribution contains code, please make sure that it follows 35 | [the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 36 | Otherwise we will have to ask you to make changes, and that's no fun for anyone. 37 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/NEWS: -------------------------------------------------------------------------------- 1 | Release 1.2 2011-05-16 2 | ---------------------- 3 | 4 | Fixes for larger databases (tested up to one billion 100-byte entries, 5 | i.e., ~100GB). 6 | 7 | (1) Place hard limit on number of level-0 files. This fixes errors 8 | of the form "too many open files". 9 | 10 | (2) Fixed memtable management. Before the fix, a heavy write burst 11 | could cause unbounded memory usage. 12 | 13 | A fix for a logging bug where the reader would incorrectly complain 14 | about corruption. 15 | 16 | Allow public access to WriteBatch contents so that users can easily 17 | wrap a DB. 18 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/TODO: -------------------------------------------------------------------------------- 1 | ss 2 | - Stats 3 | 4 | db 5 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key) 6 | that would blow away files whose ranges are entirely contained 7 | within [start_key..end_key]? For Chrome, deletion of obsolete 8 | object stores, etc. can be done in the background anyway, so 9 | probably not that important. 10 | - There have been requests for MultiGet. 11 | 12 | After a range is completely deleted, what gets rid of the 13 | corresponding files if we do no future changes to that range. Make 14 | the conditions for triggering compactions fire in more situations? 15 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/builder.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/builder.h" 6 | 7 | #include "db/filename.h" 8 | #include "db/dbformat.h" 9 | #include "db/table_cache.h" 10 | #include "db/version_edit.h" 11 | #include "leveldb/db.h" 12 | #include "leveldb/env.h" 13 | #include "leveldb/iterator.h" 14 | 15 | namespace leveldb { 16 | 17 | Status BuildTable(const std::string& dbname, 18 | Env* env, 19 | const Options& options, 20 | TableCache* table_cache, 21 | Iterator* iter, 22 | FileMetaData* meta) { 23 | Status s; 24 | meta->file_size = 0; 25 | iter->SeekToFirst(); 26 | 27 | std::string fname = TableFileName(dbname, meta->number); 28 | if (iter->Valid()) { 29 | WritableFile* file; 30 | s = env->NewWritableFile(fname, &file); 31 | if (!s.ok()) { 32 | return s; 33 | } 34 | 35 | TableBuilder* builder = new TableBuilder(options, file); 36 | meta->smallest.DecodeFrom(iter->key()); 37 | for (; iter->Valid(); iter->Next()) { 38 | Slice key = iter->key(); 39 | meta->largest.DecodeFrom(key); 40 | builder->Add(key, iter->value()); 41 | } 42 | 43 | // Finish and check for builder errors 44 | if (s.ok()) { 45 | s = builder->Finish(); 46 | if (s.ok()) { 47 | meta->file_size = builder->FileSize(); 48 | assert(meta->file_size > 0); 49 | } 50 | } else { 51 | builder->Abandon(); 52 | } 53 | delete builder; 54 | 55 | // Finish and check for file errors 56 | if (s.ok()) { 57 | s = file->Sync(); 58 | } 59 | if (s.ok()) { 60 | s = file->Close(); 61 | } 62 | delete file; 63 | file = NULL; 64 | 65 | if (s.ok()) { 66 | // Verify that the table is usable 67 | Iterator* it = table_cache->NewIterator(ReadOptions(), 68 | meta->number, 69 | meta->file_size); 70 | s = it->status(); 71 | delete it; 72 | } 73 | } 74 | 75 | // Check for input iterator errors 76 | if (!iter->status().ok()) { 77 | s = iter->status(); 78 | } 79 | 80 | if (s.ok() && meta->file_size > 0) { 81 | // Keep it 82 | } else { 83 | env->DeleteFile(fname); 84 | } 85 | return s; 86 | } 87 | 88 | } // namespace leveldb 89 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | }; 23 | 24 | bool HandleDumpCommand(Env* env, char** files, int num) { 25 | StdoutPrinter printer; 26 | bool ok = true; 27 | for (int i = 0; i < num; i++) { 28 | Status s = DumpFile(env, files[i], &printer); 29 | if (!s.ok()) { 30 | fprintf(stderr, "%s\n", s.ToString().c_str()); 31 | ok = false; 32 | } 33 | } 34 | return ok; 35 | } 36 | 37 | } // namespace 38 | } // namespace leveldb 39 | 40 | static void Usage() { 41 | fprintf( 42 | stderr, 43 | "Usage: leveldbutil command...\n" 44 | " dump files... -- dump contents of specified files\n" 45 | ); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | leveldb::Env* env = leveldb::Env::Default(); 50 | bool ok = true; 51 | if (argc < 2) { 52 | Usage(); 53 | ok = false; 54 | } else { 55 | std::string command = argv[1]; 56 | if (command == "dump") { 57 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 58 | } else { 59 | Usage(); 60 | ok = false; 61 | } 62 | } 63 | return (ok ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.md for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/memtable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_ 6 | #define STORAGE_LEVELDB_DB_MEMTABLE_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | #include "db/skiplist.h" 12 | #include "util/arena.h" 13 | 14 | namespace leveldb { 15 | 16 | class InternalKeyComparator; 17 | class Mutex; 18 | class MemTableIterator; 19 | 20 | class MemTable { 21 | public: 22 | // MemTables are reference counted. The initial reference count 23 | // is zero and the caller must call Ref() at least once. 24 | explicit MemTable(const InternalKeyComparator& comparator); 25 | 26 | // Increase reference count. 27 | void Ref() { ++refs_; } 28 | 29 | // Drop reference count. Delete if no more references exist. 30 | void Unref() { 31 | --refs_; 32 | assert(refs_ >= 0); 33 | if (refs_ <= 0) { 34 | delete this; 35 | } 36 | } 37 | 38 | // Returns an estimate of the number of bytes of data in use by this 39 | // data structure. It is safe to call when MemTable is being modified. 40 | size_t ApproximateMemoryUsage(); 41 | 42 | // Return an iterator that yields the contents of the memtable. 43 | // 44 | // The caller must ensure that the underlying MemTable remains live 45 | // while the returned iterator is live. The keys returned by this 46 | // iterator are internal keys encoded by AppendInternalKey in the 47 | // db/format.{h,cc} module. 48 | Iterator* NewIterator(); 49 | 50 | // Add an entry into memtable that maps key to value at the 51 | // specified sequence number and with the specified type. 52 | // Typically value will be empty if type==kTypeDeletion. 53 | void Add(SequenceNumber seq, ValueType type, 54 | const Slice& key, 55 | const Slice& value); 56 | 57 | // If memtable contains a value for key, store it in *value and return true. 58 | // If memtable contains a deletion for key, store a NotFound() error 59 | // in *status and return true. 60 | // Else, return false. 61 | bool Get(const LookupKey& key, std::string* value, Status* s); 62 | 63 | private: 64 | ~MemTable(); // Private since only Unref() should be used to delete it 65 | 66 | struct KeyComparator { 67 | const InternalKeyComparator comparator; 68 | explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { } 69 | int operator()(const char* a, const char* b) const; 70 | }; 71 | friend class MemTableIterator; 72 | friend class MemTableBackwardIterator; 73 | 74 | typedef SkipList Table; 75 | 76 | KeyComparator comparator_; 77 | int refs_; 78 | Arena arena_; 79 | Table table_; 80 | 81 | // No copying allowed 82 | MemTable(const MemTable&); 83 | void operator=(const MemTable&); 84 | }; 85 | 86 | } // namespace leveldb 87 | 88 | #endif // STORAGE_LEVELDB_DB_MEMTABLE_H_ 89 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/snappy_compressor.cc: -------------------------------------------------------------------------------- 1 | 2 | #ifdef SNAPPY 3 | 4 | #include "leveldb/snappy_compressor.h" 5 | 6 | #include 7 | 8 | namespace leveldb { 9 | void SnappyCompressor::compressImpl(const char* input, size_t length, ::std::string& output) const 10 | { 11 | output.resize(snappy::MaxCompressedLength(length)); 12 | size_t outlen; 13 | snappy::RawCompress(input, length, &output[0], &outlen); 14 | output.resize(outlen); 15 | } 16 | 17 | bool SnappyCompressor::decompress(const char* input, size_t length, std::string& output) const 18 | { 19 | size_t ulength; 20 | if (!snappy::GetUncompressedLength(input, length, &ulength)) 21 | return false; //could not decompress 22 | 23 | output.resize(ulength); 24 | 25 | return snappy::RawUncompress(input, length, (char*)output.data()); 26 | } 27 | 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/table_cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Thread-safe (provides internal synchronization) 6 | 7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 | 10 | #include 11 | #include 12 | #include "db/dbformat.h" 13 | #include "leveldb/cache.h" 14 | #include "leveldb/table.h" 15 | #include "port/port.h" 16 | 17 | namespace leveldb { 18 | 19 | class Env; 20 | 21 | class TableCache { 22 | public: 23 | TableCache(const std::string& dbname, const Options* options, int entries); 24 | ~TableCache(); 25 | 26 | // Return an iterator for the specified file number (the corresponding 27 | // file length must be exactly "file_size" bytes). If "tableptr" is 28 | // non-NULL, also sets "*tableptr" to point to the Table object 29 | // underlying the returned iterator, or NULL if no Table object underlies 30 | // the returned iterator. The returned "*tableptr" object is owned by 31 | // the cache and should not be deleted, and is valid for as long as the 32 | // returned iterator is live. 33 | Iterator* NewIterator(const ReadOptions& options, 34 | uint64_t file_number, 35 | uint64_t file_size, 36 | Table** tableptr = NULL); 37 | 38 | // If a seek to internal key "k" in specified file finds an entry, 39 | // call (*handle_result)(arg, found_key, found_value). 40 | Status Get(const ReadOptions& options, 41 | uint64_t file_number, 42 | uint64_t file_size, 43 | const Slice& k, 44 | void* arg, 45 | void (*handle_result)(void*, const Slice&, const Slice&)); 46 | 47 | // Evict any entry for the specified file number 48 | void Evict(uint64_t file_number); 49 | 50 | private: 51 | Env* const env_; 52 | const std::string dbname_; 53 | const Options* options_; 54 | Cache* cache_; 55 | 56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 57 | }; 58 | 59 | } // namespace leveldb 60 | 61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 62 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/zopfli_compressor.cc: -------------------------------------------------------------------------------- 1 | #ifdef ZOPFLI 2 | 3 | #include "leveldb/zopfli_compressor.h" 4 | #include "leveldb/zlib_compressor.h" 5 | 6 | #include 7 | #include 8 | #include 9 | namespace leveldb { 10 | 11 | void ZopfliCompressor::compressImpl(const char* input, size_t length, ::std::string& output) const 12 | { 13 | //extend the buffer to the worst case 14 | auto originalSize = output.size(); 15 | 16 | ZopfliOptions options; 17 | ZopfliInitOptions(&options); 18 | 19 | size_t outsize = 0; 20 | auto buffer = (char*)nullptr; 21 | ZopfliCompress(&options, ZOPFLI_FORMAT_ZLIB, (uint8_t*)input, length, (uint8_t**)&buffer, &outsize); 22 | 23 | assert(outsize > 0); 24 | 25 | output.append(buffer, outsize); 26 | free(buffer); 27 | } 28 | 29 | bool ZopfliCompressor::decompress(const char* input, size_t length, ::std::string &output) const { 30 | return ZlibCompressor::inflate(input, length, output) == Z_OK; 31 | } 32 | 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/db/zstd_compressor.cc: -------------------------------------------------------------------------------- 1 | #ifdef ZSTD 2 | 3 | #include "leveldb/zstd_compressor.h" 4 | 5 | #include 6 | 7 | void leveldb::ZstdCompressor::compressImpl(const char* input, size_t length, ::std::string& output) const 8 | { 9 | //extend the buffer to the worst case 10 | auto originalSize = output.size(); 11 | auto capacity = ZSTD_compressBound(length); 12 | output.resize(originalSize + capacity); 13 | 14 | //and then compress into it 15 | auto sz = ZSTD_compress((void*)(output.data() + originalSize), capacity, input, length, compressionLevel); 16 | 17 | assert(!ZSTD_isError(sz)); 18 | 19 | output.resize(sz + originalSize); 20 | } 21 | 22 | 23 | bool leveldb::ZstdCompressor::decompress(const char* input, size_t length, ::std::string &output) const 24 | { 25 | //extend the buffer to contain the worst case. Worst case is that input length == output length 26 | auto originalSize = output.size(); 27 | 28 | auto bufsize = length; 29 | 30 | while (true) 31 | { 32 | bufsize *= 10; //assume that the compression is compressing worse than 10%. 33 | //TODO use streams to decompress piece by piece, this is pretty wasteful for memory & re-decompressions 34 | output.resize(originalSize + bufsize); 35 | 36 | auto sz = ZSTD_decompress((void*)(output.data() + originalSize), bufsize, input, length); 37 | if (!ZSTD_isError(sz)) 38 | { 39 | output.resize(sz + originalSize); 40 | break; 41 | } 42 | } 43 | 44 | return true; 45 | } 46 | 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/comparator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class DLLX Slice; 13 | 14 | // A Comparator object provides a total order across slices that are 15 | // used as keys in an sstable or a database. A Comparator implementation 16 | // must be thread-safe since leveldb may invoke its methods concurrently 17 | // from multiple threads. 18 | class DLLX Comparator { 19 | public: 20 | virtual ~Comparator(); 21 | 22 | // Three-way comparison. Returns value: 23 | // < 0 iff "a" < "b", 24 | // == 0 iff "a" == "b", 25 | // > 0 iff "a" > "b" 26 | virtual int Compare(const Slice& a, const Slice& b) const = 0; 27 | 28 | // The name of the comparator. Used to check for comparator 29 | // mismatches (i.e., a DB created with one comparator is 30 | // accessed using a different comparator. 31 | // 32 | // The client of this package should switch to a new name whenever 33 | // the comparator implementation changes in a way that will cause 34 | // the relative ordering of any two keys to change. 35 | // 36 | // Names starting with "leveldb." are reserved and should not be used 37 | // by any clients of this package. 38 | virtual const char* Name() const = 0; 39 | 40 | // Advanced functions: these are used to reduce the space requirements 41 | // for internal data structures like index blocks. 42 | 43 | // If *start < limit, changes *start to a short string in [start,limit). 44 | // Simple comparator implementations may return with *start unchanged, 45 | // i.e., an implementation of this method that does nothing is correct. 46 | virtual void FindShortestSeparator( 47 | std::string* start, 48 | const Slice& limit) const = 0; 49 | 50 | // Changes *key to a short string >= *key. 51 | // Simple comparator implementations may return with *key unchanged, 52 | // i.e., an implementation of this method that does nothing is correct. 53 | virtual void FindShortSuccessor(std::string* key) const = 0; 54 | }; 55 | 56 | // Return a builtin comparator that uses lexicographic byte-wise 57 | // ordering. The result remains the property of this module and 58 | // must not be deleted. 59 | extern const Comparator* BytewiseComparator(); 60 | 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 64 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/compressor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace leveldb { 10 | class DLLX Slice; 11 | 12 | class DLLX Compressor 13 | { 14 | public: 15 | 16 | uint64_t inputBytes = 0, compressedBytes = 0; 17 | 18 | //an ID that has to be unique across the whole system 19 | const char uniqueCompressionID; 20 | 21 | virtual ~Compressor() {} 22 | 23 | Compressor(char uniqueCompressionID) : 24 | uniqueCompressionID(uniqueCompressionID) { 25 | 26 | } 27 | 28 | double getAverageCompression() const 29 | { 30 | return inputBytes ? ((double)compressedBytes / (double)inputBytes) : 0; 31 | } 32 | 33 | void resetAverageCompressionStats() { 34 | inputBytes = compressedBytes = 0; 35 | } 36 | 37 | void compress(const char* input, size_t length, ::std::string& output) { 38 | 39 | compressImpl(input, length, output); 40 | 41 | inputBytes += length; 42 | compressedBytes += output.length(); 43 | } 44 | 45 | void compress(const std::string& in, std::string& out) { 46 | compress(in.data(), in.length(), out); 47 | } 48 | 49 | virtual void compressImpl(const char* input, size_t length, ::std::string& output) const = 0; 50 | 51 | virtual bool decompress(const char* input, size_t length, ::std::string &output) const = 0; 52 | 53 | bool decompress(const std::string& input, ::std::string& output) const { 54 | return decompress(input.data(), input.length(), output); 55 | } 56 | 57 | protected: 58 | private: 59 | }; 60 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/decompress_allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef LEVELDB_DECOMPRESS_ALLOCATOR_H_ 4 | #define LEVELDB_DECOMPRESS_ALLOCATOR_H_ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace leveldb { 11 | class DLLX DecompressAllocator { 12 | public: 13 | virtual ~DecompressAllocator(); 14 | 15 | virtual std::string get(); 16 | virtual void release(std::string&& string); 17 | 18 | virtual void prune(); 19 | 20 | protected: 21 | std::mutex mutex; 22 | std::vector stack; 23 | }; 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/snappy_compressor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compressor.h" 4 | 5 | namespace leveldb { 6 | class DLLX SnappyCompressor : public Compressor 7 | { 8 | public: 9 | 10 | static const char SERIALIZE_ID = 1; 11 | 12 | virtual ~SnappyCompressor() {} 13 | 14 | SnappyCompressor() : 15 | Compressor(SERIALIZE_ID) { 16 | 17 | } 18 | 19 | virtual void compressImpl(const char* input, size_t length, ::std::string& output) const override; 20 | 21 | virtual bool decompress(const char* input, size_t length, ::std::string& output) const override; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include 26 | #include "leveldb/status.h" 27 | 28 | namespace leveldb { 29 | 30 | class DLLX Slice; 31 | 32 | class DLLX WriteBatch { 33 | public: 34 | WriteBatch(); 35 | ~WriteBatch(); 36 | 37 | // Store the mapping "key->value" in the database. 38 | void Put(const Slice& key, const Slice& value); 39 | 40 | // If the database contains a mapping for "key", erase it. Else do nothing. 41 | void Delete(const Slice& key); 42 | 43 | // Clear all updates buffered in this batch. 44 | void Clear(); 45 | 46 | // The size of the database changes caused by this batch. 47 | // 48 | // This number is tied to implementation details, and may change across 49 | // releases. It is intended for LevelDB usage metrics. 50 | size_t ApproximateSize(); 51 | 52 | // Support for iterating over the contents of a batch. 53 | class DLLX Handler { 54 | public: 55 | virtual ~Handler(); 56 | virtual void Put(const Slice& key, const Slice& value) = 0; 57 | virtual void Delete(const Slice& key) = 0; 58 | }; 59 | Status Iterate(Handler* handler) const; 60 | 61 | private: 62 | friend class WriteBatchInternal; 63 | 64 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 65 | 66 | // Intentionally copyable 67 | }; 68 | 69 | } // namespace leveldb 70 | 71 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 72 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/zlib_compressor.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "leveldb/compressor.h" 5 | 6 | namespace leveldb { 7 | 8 | class DLLX ZlibCompressorBase : public Compressor 9 | { 10 | public: 11 | int inflate(const char* input, size_t length, ::std::string &output) const; 12 | 13 | const int compressionLevel; 14 | const bool raw; 15 | 16 | virtual ~ZlibCompressorBase() { 17 | 18 | } 19 | 20 | ZlibCompressorBase(char uniqueCompressionID, int compressionLevel, bool raw) : 21 | Compressor(uniqueCompressionID), 22 | compressionLevel(compressionLevel), 23 | raw(raw) 24 | { 25 | assert(compressionLevel >= -1 && compressionLevel <= 9); 26 | } 27 | 28 | virtual void compressImpl(const char* input, size_t length, ::std::string& output) const override; 29 | 30 | virtual bool decompress(const char* input, size_t length, ::std::string &output) const override; 31 | 32 | private: 33 | 34 | int _window() const; 35 | 36 | }; 37 | 38 | class DLLX ZlibCompressor : public ZlibCompressorBase { 39 | public: 40 | static const int SERIALIZE_ID = 2; 41 | 42 | ZlibCompressor(int compressionLevel = -1) : 43 | ZlibCompressorBase(SERIALIZE_ID, compressionLevel, false) { 44 | 45 | } 46 | }; 47 | 48 | class DLLX ZlibCompressorRaw : public ZlibCompressorBase { 49 | public: 50 | static const int SERIALIZE_ID = 4; 51 | 52 | ZlibCompressorRaw(int compressionLevel = -1) : 53 | ZlibCompressorBase(SERIALIZE_ID, compressionLevel, true) { 54 | 55 | } 56 | }; 57 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/zopfli_compressor.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "leveldb/compressor.h" 5 | 6 | namespace leveldb { 7 | 8 | class DLLX ZopfliCompressor : public Compressor 9 | { 10 | public: 11 | static const int SERIALIZE_ID = 2; //Same as ZLib since it is a replacement 12 | 13 | ZopfliCompressor() : Compressor(SERIALIZE_ID) {} 14 | 15 | virtual ~ZopfliCompressor() {} 16 | 17 | virtual void compressImpl(const char* input, size_t length, ::std::string& output) const override; 18 | 19 | virtual bool decompress(const char* input, size_t length, ::std::string &output) const override; 20 | 21 | private: 22 | }; 23 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/include/leveldb/zstd_compressor.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "leveldb/compressor.h" 5 | 6 | namespace leveldb { 7 | 8 | class DLLX ZstdCompressor : public Compressor 9 | { 10 | public: 11 | static const int SERIALIZE_ID = 3; 12 | 13 | const int compressionLevel; 14 | 15 | virtual ~ZstdCompressor() { 16 | 17 | } 18 | 19 | ZstdCompressor(int compressionLevel = -1) : 20 | Compressor(SERIALIZE_ID), 21 | compressionLevel(compressionLevel) 22 | { 23 | assert(compressionLevel >= -1 && compressionLevel <= 9); 24 | } 25 | 26 | virtual void compressImpl(const char* input, size_t length, ::std::string& output) const override; 27 | 28 | virtual bool decompress(const char* input, size_t length, ::std::string &output) const override; 29 | 30 | private: 31 | 32 | }; 33 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/issues/issue178_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 178: a manual compaction causes deleted data to reappear. 6 | #include 7 | #include 8 | #include 9 | 10 | #include "leveldb/db.h" 11 | #include "leveldb/write_batch.h" 12 | #include "util/testharness.h" 13 | 14 | namespace { 15 | 16 | const int kNumKeys = 1100000; 17 | 18 | std::string Key1(int i) { 19 | char buf[100]; 20 | snprintf(buf, sizeof(buf), "my_key_%d", i); 21 | return buf; 22 | } 23 | 24 | std::string Key2(int i) { 25 | return Key1(i) + "_xxx"; 26 | } 27 | 28 | class Issue178 { }; 29 | 30 | TEST(Issue178, Test) { 31 | // Get rid of any state from an old run. 32 | std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test"; 33 | DestroyDB(dbpath, leveldb::Options()); 34 | 35 | // Open database. Disable compression since it affects the creation 36 | // of layers and the code below is trying to test against a very 37 | // specific scenario. 38 | leveldb::DB* db; 39 | leveldb::Options db_options; 40 | db_options.create_if_missing = true; 41 | ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db)); 42 | 43 | // create first key range 44 | leveldb::WriteBatch batch; 45 | for (size_t i = 0; i < kNumKeys; i++) { 46 | batch.Put(Key1(i), "value for range 1 key"); 47 | } 48 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 49 | 50 | // create second key range 51 | batch.Clear(); 52 | for (size_t i = 0; i < kNumKeys; i++) { 53 | batch.Put(Key2(i), "value for range 2 key"); 54 | } 55 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 56 | 57 | // delete second key range 58 | batch.Clear(); 59 | for (size_t i = 0; i < kNumKeys; i++) { 60 | batch.Delete(Key2(i)); 61 | } 62 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 63 | 64 | // compact database 65 | std::string start_key = Key1(0); 66 | std::string end_key = Key1(kNumKeys - 1); 67 | leveldb::Slice least(start_key.data(), start_key.size()); 68 | leveldb::Slice greatest(end_key.data(), end_key.size()); 69 | 70 | // commenting out the line below causes the example to work correctly 71 | db->CompactRange(&least, &greatest); 72 | 73 | // count the keys 74 | leveldb::Iterator* iter = db->NewIterator(leveldb::ReadOptions()); 75 | size_t num_keys = 0; 76 | for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { 77 | num_keys++; 78 | } 79 | delete iter; 80 | ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys"; 81 | 82 | // close database 83 | delete db; 84 | DestroyDB(dbpath, leveldb::Options()); 85 | } 86 | 87 | } // anonymous namespace 88 | 89 | int main(int argc, char** argv) { 90 | return leveldb::test::RunAllTests(); 91 | } 92 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/mcpe_sample_setup.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | 4 | class NullLogger : public leveldb::Logger { 5 | public: 6 | void Logv(const char*, va_list) override { 7 | } 8 | }; 9 | 10 | leveldb::Options options; 11 | 12 | //create a bloom filter to quickly tell if a key is in the database or not 13 | options.filter_policy = leveldb::NewBloomFilterPolicy(10); 14 | 15 | //create a 40 mb cache (we use this on ~1gb devices) 16 | options.block_cache = leveldb::NewLRUCache(40 * 1024 * 1024); 17 | 18 | //create a 4mb write buffer, to improve compression and touch the disk less 19 | options.write_buffer_size = 4 * 1024 * 1024; 20 | 21 | //disable internal logging. The default logger will still print out things to a file 22 | options.info_log = new NullLogger(); 23 | 24 | //use the new raw-zip compressor to write (and read) 25 | options.compressors[0] = new leveldb::ZlibCompressorRaw(-1); 26 | 27 | //also setup the old, slower compressor for backwards compatibility. This will only be used to read old compressed blocks. 28 | options.compressors[1] = new leveldb::ZlibCompressor(); 29 | 30 | 31 | //create a reusable memory space for decompression so it allocates less 32 | leveldb::ReadOptions readOptions; 33 | readOptions.decompress_allocator = new leveldb::DecompressAllocator(); 34 | 35 | 36 | //... init leveldb with Options and read with ReadOptions 37 | } -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_POSIX) || defined(LEVELDB_PLATFORM_ANDROID) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #elif defined(WIN32) 18 | # include "port/port_win.h" 19 | #endif 20 | 21 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 22 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #if defined(LEVELDB_PLATFORM_POSIX) || defined(LEVELDB_PLATFORM_ANDROID) 6 | 7 | #include "port/port_posix.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | namespace port { 15 | 16 | static void PthreadCall(const char* label, int result) { 17 | if (result != 0) { 18 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 19 | abort(); 20 | } 21 | } 22 | 23 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 24 | 25 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 26 | 27 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 28 | 29 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 30 | 31 | CondVar::CondVar(Mutex* mu) 32 | : mu_(mu) { 33 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 34 | } 35 | 36 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 37 | 38 | void CondVar::Wait() { 39 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 40 | } 41 | 42 | void CondVar::Signal() { 43 | PthreadCall("signal", pthread_cond_signal(&cv_)); 44 | } 45 | 46 | void CondVar::SignalAll() { 47 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 48 | } 49 | 50 | void InitOnce(OnceType* once, void (*initializer)()) { 51 | PthreadCall("once", pthread_once(once, initializer)); 52 | } 53 | 54 | } // namespace port 55 | } // namespace leveldb 56 | #endif -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/filter_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A filter block is stored near the end of a Table file. It contains 6 | // filters (e.g., bloom filters) for all data blocks in the table combined 7 | // into a single filter block. 8 | 9 | #ifndef STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 10 | #define STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "leveldb/slice.h" 17 | #include "util/hash.h" 18 | 19 | namespace leveldb { 20 | 21 | class FilterPolicy; 22 | 23 | // A FilterBlockBuilder is used to construct all of the filters for a 24 | // particular Table. It generates a single string which is stored as 25 | // a special block in the Table. 26 | // 27 | // The sequence of calls to FilterBlockBuilder must match the regexp: 28 | // (StartBlock AddKey*)* Finish 29 | class FilterBlockBuilder { 30 | public: 31 | explicit FilterBlockBuilder(const FilterPolicy*); 32 | 33 | void StartBlock(uint64_t block_offset); 34 | void AddKey(const Slice& key); 35 | Slice Finish(); 36 | 37 | private: 38 | void GenerateFilter(); 39 | 40 | const FilterPolicy* policy_; 41 | std::string keys_; // Flattened key contents 42 | std::vector start_; // Starting index in keys_ of each key 43 | std::string result_; // Filter data computed so far 44 | std::vector tmp_keys_; // policy_->CreateFilter() argument 45 | std::vector filter_offsets_; 46 | 47 | // No copying allowed 48 | FilterBlockBuilder(const FilterBlockBuilder&); 49 | void operator=(const FilterBlockBuilder&); 50 | }; 51 | 52 | class FilterBlockReader { 53 | public: 54 | // REQUIRES: "contents" and *policy must stay live while *this is live. 55 | FilterBlockReader(const FilterPolicy* policy, const Slice& contents); 56 | bool KeyMayMatch(uint64_t block_offset, const Slice& key); 57 | 58 | private: 59 | const FilterPolicy* policy_; 60 | const char* data_; // Pointer to filter data (at block-start) 61 | const char* offset_; // Pointer to beginning of offset array (at block-end) 62 | size_t num_; // Number of entries in offset array 63 | size_t base_lg_; // Encoding parameter (see kFilterBaseLg in .cc file) 64 | }; 65 | 66 | } 67 | 68 | #endif // STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 69 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/iterator_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | #include "leveldb/slice.h" 10 | 11 | namespace leveldb { 12 | 13 | // A internal wrapper class with an interface similar to Iterator that 14 | // caches the valid() and key() results for an underlying iterator. 15 | // This can help avoid virtual function calls and also gives better 16 | // cache locality. 17 | class IteratorWrapper { 18 | public: 19 | IteratorWrapper(): iter_(NULL), valid_(false) { } 20 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 21 | Set(iter); 22 | } 23 | ~IteratorWrapper() { delete iter_; } 24 | Iterator* iter() const { return iter_; } 25 | 26 | // Takes ownership of "iter" and will delete it when destroyed, or 27 | // when Set() is invoked again. 28 | void Set(Iterator* iter) { 29 | delete iter_; 30 | iter_ = iter; 31 | if (iter_ == NULL) { 32 | valid_ = false; 33 | } else { 34 | Update(); 35 | } 36 | } 37 | 38 | 39 | // Iterator interface methods 40 | bool Valid() const { return valid_; } 41 | Slice key() const { assert(Valid()); return key_; } 42 | Slice value() const { assert(Valid()); return iter_->value(); } 43 | // Methods below require iter() != NULL 44 | Status status() const { assert(iter_); return iter_->status(); } 45 | void Next() { assert(iter_); iter_->Next(); Update(); } 46 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 47 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 48 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 49 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 50 | 51 | private: 52 | void Update() { 53 | valid_ = iter_->Valid(); 54 | if (valid_) { 55 | key_ = iter_->key(); 56 | } 57 | } 58 | 59 | Iterator* iter_; 60 | bool valid_; 61 | Slice key_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 67 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/Filepath.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_MSC_VER) 4 | #include 5 | #include 6 | #include 7 | #endif 8 | 9 | namespace port { 10 | 11 | #if defined(_MSC_VER) 12 | // std::strings won't work for windows as all their STL/Win32 APIs assume char* are pure ASCII 13 | // "luckily", there is an unofficial parameter for iostream that takes a wide character Unicode string 14 | typedef std::wstring filepath; 15 | typedef wchar_t filepath_char; 16 | #define _FILE_STR(str) L ## str 17 | #else 18 | typedef std::string filepath; 19 | typedef char filepath_char; 20 | #define _FILE_STR(str) str 21 | #endif 22 | 23 | 24 | inline filepath toFilePath(const std::string &string) { 25 | #if defined(_MSC_VER) 26 | std::wstring_convert, wchar_t> converter; 27 | return std::move(converter.from_bytes(string)); 28 | #else 29 | return std::move(string); 30 | #endif 31 | } 32 | 33 | #if defined(_MSC_VER) 34 | inline FILE* fopen_mb(const filepath_char* filename, const filepath_char* mode) { 35 | FILE* file = nullptr; 36 | 37 | errno_t error = _wfopen_s(&file, filename, mode); 38 | _set_errno(error); 39 | 40 | return file; 41 | } 42 | 43 | // this function will silently allocate memory on windows to convert char* to wchar_t* 44 | inline FILE* fopen_mb(const char* const filename, const filepath_char* mode) { 45 | filepath path = toFilePath(filename); 46 | 47 | return port::fopen_mb(path.c_str(), mode); 48 | } 49 | #else 50 | inline FILE* fopen_mb(const filepath_char* filename, const filepath_char* mode) { 51 | return ::fopen(filename, mode); 52 | } 53 | #endif 54 | } 55 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/arena.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | #include 7 | 8 | namespace leveldb { 9 | 10 | static const int kBlockSize = 4096; 11 | 12 | Arena::Arena() : memory_usage_(0) { 13 | alloc_ptr_ = NULL; // First allocation will allocate a block 14 | alloc_bytes_remaining_ = 0; 15 | } 16 | 17 | Arena::~Arena() { 18 | for (size_t i = 0; i < blocks_.size(); i++) { 19 | delete[] blocks_[i]; 20 | } 21 | } 22 | 23 | char* Arena::AllocateFallback(size_t bytes) { 24 | if (bytes > kBlockSize / 4) { 25 | // Object is more than a quarter of our block size. Allocate it separately 26 | // to avoid wasting too much space in leftover bytes. 27 | char* result = AllocateNewBlock(bytes); 28 | return result; 29 | } 30 | 31 | // We waste the remaining space in the current block. 32 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 33 | alloc_bytes_remaining_ = kBlockSize; 34 | 35 | char* result = alloc_ptr_; 36 | alloc_ptr_ += bytes; 37 | alloc_bytes_remaining_ -= bytes; 38 | return result; 39 | } 40 | 41 | char* Arena::AllocateAligned(size_t bytes) { 42 | const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8; 43 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 44 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 45 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 46 | size_t needed = bytes + slop; 47 | char* result; 48 | if (needed <= alloc_bytes_remaining_) { 49 | result = alloc_ptr_ + slop; 50 | alloc_ptr_ += needed; 51 | alloc_bytes_remaining_ -= needed; 52 | } else { 53 | // AllocateFallback always returned aligned memory 54 | result = AllocateFallback(bytes); 55 | } 56 | assert((reinterpret_cast(result) & (align-1)) == 0); 57 | return result; 58 | } 59 | 60 | char* Arena::AllocateNewBlock(size_t block_bytes) { 61 | char* result = new char[block_bytes]; 62 | blocks_.push_back(result); 63 | memory_usage_.NoBarrier_Store( 64 | reinterpret_cast(MemoryUsage() + block_bytes + sizeof(char*))); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class Arena { 17 | public: 18 | Arena(); 19 | ~Arena(); 20 | 21 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 22 | char* Allocate(size_t bytes); 23 | 24 | // Allocate memory with the normal alignment guarantees provided by malloc 25 | char* AllocateAligned(size_t bytes); 26 | 27 | // Returns an estimate of the total memory usage of data allocated 28 | // by the arena. 29 | size_t MemoryUsage() const { 30 | return reinterpret_cast(memory_usage_.NoBarrier_Load()); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Total memory usage of the arena. 45 | port::AtomicPointer memory_usage_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/comparator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/slice.h" 9 | #include "port/port.h" 10 | #include "util/logging.h" 11 | 12 | namespace leveldb { 13 | 14 | Comparator::~Comparator() { } 15 | 16 | namespace { 17 | class BytewiseComparatorImpl : public Comparator { 18 | public: 19 | BytewiseComparatorImpl() { } 20 | 21 | virtual const char* Name() const { 22 | return "leveldb.BytewiseComparator"; 23 | } 24 | 25 | virtual int Compare(const Slice& a, const Slice& b) const { 26 | return a.compare(b); 27 | } 28 | 29 | virtual void FindShortestSeparator( 30 | std::string* start, 31 | const Slice& limit) const { 32 | // Find length of common prefix 33 | size_t min_length = std::min(start->size(), limit.size()); 34 | size_t diff_index = 0; 35 | while ((diff_index < min_length) && 36 | ((*start)[diff_index] == limit[diff_index])) { 37 | diff_index++; 38 | } 39 | 40 | if (diff_index >= min_length) { 41 | // Do not shorten if one string is a prefix of the other 42 | } else { 43 | uint8_t diff_byte = static_cast((*start)[diff_index]); 44 | if (diff_byte < static_cast(0xff) && 45 | diff_byte + 1 < static_cast(limit[diff_index])) { 46 | (*start)[diff_index]++; 47 | start->resize(diff_index + 1); 48 | assert(Compare(*start, limit) < 0); 49 | } 50 | } 51 | } 52 | 53 | virtual void FindShortSuccessor(std::string* key) const { 54 | // Find first character that can be incremented 55 | size_t n = key->size(); 56 | for (size_t i = 0; i < n; i++) { 57 | const uint8_t byte = (*key)[i]; 58 | if (byte != static_cast(0xff)) { 59 | (*key)[i] = byte + 1; 60 | key->resize(i+1); 61 | return; 62 | } 63 | } 64 | // *key is a run of 0xffs. Leave it alone. 65 | } 66 | }; 67 | } // namespace 68 | 69 | static port::OnceType once = LEVELDB_ONCE_INIT; 70 | static const Comparator* bytewise; 71 | 72 | static void InitModule() { 73 | bytewise = new BytewiseComparatorImpl; 74 | } 75 | 76 | const Comparator* BytewiseComparator() { 77 | port::InitOnce(&once, InitModule); 78 | return bytewise; 79 | } 80 | 81 | } // namespace leveldb 82 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/env.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/env.h" 6 | 7 | namespace leveldb { 8 | 9 | Env::~Env() { 10 | } 11 | 12 | Status Env::NewAppendableFile(const std::string& fname, WritableFile** result) { 13 | return Status::NotSupported("NewAppendableFile", fname); 14 | } 15 | 16 | SequentialFile::~SequentialFile() { 17 | } 18 | 19 | RandomAccessFile::~RandomAccessFile() { 20 | } 21 | 22 | WritableFile::~WritableFile() { 23 | } 24 | 25 | Logger::~Logger() { 26 | } 27 | 28 | FileLock::~FileLock() { 29 | } 30 | 31 | void Log(Logger* info_log, const char* format, ...) { 32 | if (info_log != NULL) { 33 | va_list ap; 34 | va_start(ap, format); 35 | info_log->Logv(format, ap); 36 | va_end(ap); 37 | } 38 | } 39 | 40 | static Status DoWriteStringToFile(Env* env, const Slice& data, 41 | const std::string& fname, 42 | bool should_sync) { 43 | WritableFile* file; 44 | Status s = env->NewWritableFile(fname, &file); 45 | if (!s.ok()) { 46 | return s; 47 | } 48 | s = file->Append(data); 49 | if (s.ok() && should_sync) { 50 | s = file->Sync(); 51 | } 52 | if (s.ok()) { 53 | s = file->Close(); 54 | } 55 | delete file; // Will auto-close if we did not close above 56 | if (!s.ok()) { 57 | env->DeleteFile(fname); 58 | } 59 | return s; 60 | } 61 | 62 | Status WriteStringToFile(Env* env, const Slice& data, 63 | const std::string& fname) { 64 | return DoWriteStringToFile(env, data, fname, false); 65 | } 66 | 67 | Status WriteStringToFileSync(Env* env, const Slice& data, 68 | const std::string& fname) { 69 | return DoWriteStringToFile(env, data, fname, true); 70 | } 71 | 72 | Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { 73 | data->clear(); 74 | SequentialFile* file; 75 | Status s = env->NewSequentialFile(fname, &file); 76 | if (!s.ok()) { 77 | return s; 78 | } 79 | static const int kBufferSize = 8192; 80 | char* space = new char[kBufferSize]; 81 | while (true) { 82 | Slice fragment; 83 | s = file->Read(kBufferSize, &fragment, space); 84 | if (!s.ok()) { 85 | break; 86 | } 87 | data->append(fragment.data(), fragment.size()); 88 | if (fragment.empty()) { 89 | break; 90 | } 91 | } 92 | delete[] space; 93 | delete file; 94 | return s; 95 | } 96 | 97 | EnvWrapper::~EnvWrapper() { 98 | } 99 | 100 | } // namespace leveldb 101 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/env_posix_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/env.h" 6 | 7 | #include "port/port.h" 8 | #include "util/testharness.h" 9 | #include "util/env_posix_test_helper.h" 10 | 11 | namespace leveldb { 12 | 13 | static const int kDelayMicros = 100000; 14 | static const int kReadOnlyFileLimit = 4; 15 | static const int kMMapLimit = 4; 16 | 17 | class EnvPosixTest { 18 | public: 19 | Env* env_; 20 | EnvPosixTest() : env_(Env::Default()) { } 21 | 22 | static void SetFileLimits(int read_only_file_limit, int mmap_limit) { 23 | EnvPosixTestHelper::SetReadOnlyFDLimit(read_only_file_limit); 24 | EnvPosixTestHelper::SetReadOnlyMMapLimit(mmap_limit); 25 | } 26 | }; 27 | 28 | TEST(EnvPosixTest, TestOpenOnRead) { 29 | // Write some test data to a single file that will be opened |n| times. 30 | std::string test_dir; 31 | ASSERT_OK(env_->GetTestDirectory(&test_dir)); 32 | std::string test_file = test_dir + "/open_on_read.txt"; 33 | 34 | FILE* f = fopen(test_file.c_str(), "w"); 35 | ASSERT_TRUE(f != NULL); 36 | const char kFileData[] = "abcdefghijklmnopqrstuvwxyz"; 37 | fputs(kFileData, f); 38 | fclose(f); 39 | 40 | // Open test file some number above the sum of the two limits to force 41 | // open-on-read behavior of POSIX Env leveldb::RandomAccessFile. 42 | const int kNumFiles = kReadOnlyFileLimit + kMMapLimit + 5; 43 | leveldb::RandomAccessFile* files[kNumFiles] = {0}; 44 | for (int i = 0; i < kNumFiles; i++) { 45 | ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i])); 46 | } 47 | char scratch; 48 | Slice read_result; 49 | for (int i = 0; i < kNumFiles; i++) { 50 | ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch)); 51 | ASSERT_EQ(kFileData[i], read_result[0]); 52 | } 53 | for (int i = 0; i < kNumFiles; i++) { 54 | delete files[i]; 55 | } 56 | ASSERT_OK(env_->DeleteFile(test_file)); 57 | } 58 | 59 | } // namespace leveldb 60 | 61 | int main(int argc, char** argv) { 62 | // All tests currently run with the same read-only file limits. 63 | leveldb::EnvPosixTest::SetFileLimits(leveldb::kReadOnlyFileLimit, 64 | leveldb::kMMapLimit); 65 | return leveldb::test::RunAllTests(); 66 | } 67 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/env_posix_test_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 6 | #define STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class EnvPosixTest; 11 | 12 | // A helper for the POSIX Env to facilitate testing. 13 | class EnvPosixTestHelper { 14 | private: 15 | friend class EnvPosixTest; 16 | 17 | // Set the maximum number of read-only files that will be opened. 18 | // Must be called before creating an Env. 19 | static void SetReadOnlyFDLimit(int limit); 20 | 21 | // Set the maximum number of read-only files that will be mapped via mmap. 22 | // Must be called before creating an Env. 23 | static void SetReadOnlyMMapLimit(int limit); 24 | }; 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 29 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/env_win.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreatorMC/MapPaintingEditor/1145ec8fbf6fe03be9271ef4230ed59f18cbe890/android-leveldb-master/library/src/main/jni/leveldb/util/env_win.cc -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/env_winrt.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreatorMC/MapPaintingEditor/1145ec8fbf6fe03be9271ef4230ed59f18cbe890/android-leveldb-master/library/src/main/jni/leveldb/util/env_winrt.cc -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = (uint32_t)seed ^ ((uint32_t)n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/hash_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | max_file_size(2<<20), 25 | reuse_logs(false), 26 | filter_policy(NULL) { 27 | 28 | memset(compressors, 0, sizeof(compressors)); 29 | } 30 | } // namespace leveldb 31 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/posix_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Logger implementation that can be shared by all environments 6 | // where enough posix functionality is available. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 9 | #define STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "leveldb/env.h" 16 | 17 | namespace leveldb { 18 | 19 | class PosixLogger : public Logger { 20 | private: 21 | FILE* file_; 22 | uint64_t (*gettid_)(); // Return the thread id for the current thread 23 | public: 24 | PosixLogger(FILE* f, uint64_t (*gettid)()) : file_(f), gettid_(gettid) { } 25 | virtual ~PosixLogger() { 26 | fclose(file_); 27 | } 28 | virtual void Logv(const char* format, va_list ap) { 29 | const uint64_t thread_id = (*gettid_)(); 30 | 31 | // We try twice: the first time with a fixed-size stack allocated buffer, 32 | // and the second time with a much larger dynamically allocated buffer. 33 | char buffer[500]; 34 | for (int iter = 0; iter < 2; iter++) { 35 | char* base; 36 | int bufsize; 37 | if (iter == 0) { 38 | bufsize = sizeof(buffer); 39 | base = buffer; 40 | } else { 41 | bufsize = 30000; 42 | base = new char[bufsize]; 43 | } 44 | char* p = base; 45 | char* limit = base + bufsize; 46 | 47 | struct timeval now_tv; 48 | gettimeofday(&now_tv, NULL); 49 | const time_t seconds = now_tv.tv_sec; 50 | struct tm t; 51 | localtime_r(&seconds, &t); 52 | p += snprintf(p, limit - p, 53 | "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", 54 | t.tm_year + 1900, 55 | t.tm_mon + 1, 56 | t.tm_mday, 57 | t.tm_hour, 58 | t.tm_min, 59 | t.tm_sec, 60 | static_cast(now_tv.tv_usec), 61 | static_cast(thread_id)); 62 | 63 | // Print the message 64 | if (p < limit) { 65 | va_list backup_ap; 66 | va_copy(backup_ap, ap); 67 | p += vsnprintf(p, limit - p, format, backup_ap); 68 | va_end(backup_ap); 69 | } 70 | 71 | // Truncate to available space if necessary 72 | if (p >= limit) { 73 | if (iter == 0) { 74 | continue; // Try again with larger buffer 75 | } else { 76 | p = limit - 1; 77 | } 78 | } 79 | 80 | // Add newline if necessary 81 | if (p == base || p[-1] != '\n') { 82 | *p++ = '\n'; 83 | } 84 | 85 | assert(p <= limit); 86 | fwrite(base, 1, p - base, file_); 87 | fflush(file_); 88 | if (base != buffer) { 89 | delete[] base; 90 | } 91 | break; 92 | } 93 | } 94 | }; 95 | 96 | } // namespace leveldb 97 | 98 | #endif // STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 99 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/random.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_ 6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | // A very simple random number generator. Not especially good at 13 | // generating truly random bits, but good enough for our needs in this 14 | // package. 15 | class Random { 16 | private: 17 | uint32_t seed_; 18 | public: 19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { 20 | // Avoid bad seeds. 21 | if (seed_ == 0 || seed_ == 2147483647L) { 22 | seed_ = 1; 23 | } 24 | } 25 | uint32_t Next() { 26 | static const uint32_t M = 2147483647L; // 2^31-1 27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 28 | // We are computing 29 | // seed_ = (seed_ * A) % M, where M = 2^31-1 30 | // 31 | // seed_ must not be zero or M, or else all subsequent computed values 32 | // will be zero or M respectively. For all other values, seed_ will end 33 | // up cycling through every number in [1,M-1] 34 | uint64_t product = seed_ * A; 35 | 36 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 37 | seed_ = static_cast((product >> 31) + (product & M)); 38 | // The first reduction may overflow by 1 bit, so we may need to 39 | // repeat. mod == M is not possible; using > allows the faster 40 | // sign-bit-based test. 41 | if (seed_ > M) { 42 | seed_ -= M; 43 | } 44 | return seed_; 45 | } 46 | // Returns a uniformly distributed value in the range [0..n-1] 47 | // REQUIRES: n > 0 48 | uint32_t Uniform(int n) { return Next() % n; } 49 | 50 | // Randomly returns true ~"1/n" of the time, and false otherwise. 51 | // REQUIRES: n > 0 52 | bool OneIn(int n) { return (Next() % n) == 0; } 53 | 54 | // Skewed: pick "base" uniformly from range [0,max_log] and then 55 | // return "base" random bits. The effect is to pick a number in the 56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 57 | uint32_t Skewed(int max_log) { 58 | return Uniform(1 << Uniform(max_log + 1)); 59 | } 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 65 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/status.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "port/port.h" 7 | #include "leveldb/status.h" 8 | 9 | namespace leveldb { 10 | 11 | const char* Status::CopyState(const char* state) { 12 | uint32_t size; 13 | memcpy(&size, state, sizeof(size)); 14 | char* result = new char[size + 5]; 15 | memcpy(result, state, size + 5); 16 | return result; 17 | } 18 | 19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) { 20 | assert(code != kOk); 21 | const uint32_t len1 = (uint32_t)msg.size(); 22 | const uint32_t len2 = (uint32_t)msg2.size(); 23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 24 | char* result = new char[size + 5]; 25 | memcpy(result, &size, sizeof(size)); 26 | result[4] = static_cast(code); 27 | memcpy(result + 5, msg.data(), len1); 28 | if (len2) { 29 | result[5 + len1] = ':'; 30 | result[6 + len1] = ' '; 31 | memcpy(result + 7 + len1, msg2.data(), len2); 32 | } 33 | state_ = result; 34 | } 35 | 36 | std::string Status::ToString() const { 37 | if (state_ == NULL) { 38 | return "OK"; 39 | } else { 40 | char tmp[30]; 41 | const char* type; 42 | switch (code()) { 43 | case kOk: 44 | type = "OK"; 45 | break; 46 | case kNotFound: 47 | type = "NotFound: "; 48 | break; 49 | case kCorruption: 50 | type = "Corruption: "; 51 | break; 52 | case kNotSupported: 53 | type = "Not implemented: "; 54 | break; 55 | case kInvalidArgument: 56 | type = "Invalid argument: "; 57 | break; 58 | case kIOError: 59 | type = "IO error: "; 60 | break; 61 | default: 62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 63 | static_cast(code())); 64 | type = tmp; 65 | break; 66 | } 67 | std::string result(type); 68 | uint32_t length; 69 | memcpy(&length, state_, sizeof(length)); 70 | result.append(state_ + 5, length); 71 | return result; 72 | } 73 | } 74 | 75 | } // namespace leveldb 76 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/testutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 7 | 8 | #include "leveldb/env.h" 9 | #include "leveldb/slice.h" 10 | #include "util/random.h" 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | // Store in *dst a random string of length "len" and return a Slice that 16 | // references the generated data. 17 | extern Slice RandomString(Random* rnd, int len, std::string* dst); 18 | 19 | // Return a random key with the specified length that may contain interesting 20 | // characters (e.g. \x00, \xff, etc.). 21 | extern std::string RandomKey(Random* rnd, int len); 22 | 23 | // Store in *dst a string of length "len" that will compress to 24 | // "N*compressed_fraction" bytes and return a Slice that references 25 | // the generated data. 26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 27 | size_t len, std::string* dst); 28 | 29 | // A wrapper that allows injection of errors. 30 | class ErrorEnv : public EnvWrapper { 31 | public: 32 | bool writable_file_error_; 33 | int num_writable_file_errors_; 34 | 35 | ErrorEnv() : EnvWrapper(Env::Default()), 36 | writable_file_error_(false), 37 | num_writable_file_errors_(0) { } 38 | 39 | virtual Status NewWritableFile(const std::string& fname, 40 | WritableFile** result) { 41 | if (writable_file_error_) { 42 | ++num_writable_file_errors_; 43 | *result = NULL; 44 | return Status::IOError(fname, "fake error"); 45 | } 46 | return target()->NewWritableFile(fname, result); 47 | } 48 | 49 | virtual Status NewAppendableFile(const std::string& fname, 50 | WritableFile** result) { 51 | if (writable_file_error_) { 52 | ++num_writable_file_errors_; 53 | *result = NULL; 54 | return Status::IOError(fname, "fake error"); 55 | } 56 | return target()->NewAppendableFile(fname, result); 57 | } 58 | }; 59 | 60 | } // namespace test 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 64 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/win_logger.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/win_logger.h" 6 | 7 | #ifdef WIN32 8 | 9 | #include 10 | 11 | namespace leveldb { 12 | 13 | void WinLogger::Logv(const char* format, va_list ap) { 14 | const uint64_t thread_id = static_cast(::GetCurrentThreadId()); 15 | 16 | // We try twice: the first time with a fixed-size stack allocated buffer, 17 | // and the second time with a much larger dynamically allocated buffer. 18 | char buffer[500]; 19 | 20 | for (int iter = 0; iter < 2; iter++) { 21 | char* base; 22 | int bufsize; 23 | if (iter == 0) { 24 | bufsize = sizeof(buffer); 25 | base = buffer; 26 | } else { 27 | bufsize = 30000; 28 | base = new char[bufsize]; 29 | } 30 | 31 | char* p = base; 32 | char* limit = base + bufsize; 33 | 34 | SYSTEMTIME st; 35 | 36 | // GetSystemTime returns UTC time, we want local time! 37 | ::GetLocalTime(&st); 38 | 39 | p += _snprintf_s(p, limit - p, _TRUNCATE, 40 | "%04d/%02d/%02d-%02d:%02d:%02d.%03d %llx ", 41 | st.wYear, 42 | st.wMonth, 43 | st.wDay, 44 | st.wHour, 45 | st.wMinute, 46 | st.wSecond, 47 | st.wMilliseconds, 48 | static_cast(thread_id)); 49 | 50 | // Print the message 51 | if (p < limit) { 52 | va_list backup_ap = ap; 53 | p += vsnprintf(p, limit - p, format, backup_ap); 54 | va_end(backup_ap); 55 | } 56 | 57 | // Truncate to available space if necessary 58 | if (p >= limit) { 59 | if (iter == 0) { 60 | continue; // Try again with larger buffer 61 | } else { 62 | p = limit - 1; 63 | } 64 | } 65 | 66 | // Add newline if necessary 67 | if (p == base || p[-1] != '\n') { 68 | *p++ = '\n'; 69 | } 70 | 71 | assert(p <= limit); 72 | fwrite(base, 1, p - base, file_); 73 | fflush(file_); 74 | if (base != buffer) { 75 | delete[] base; 76 | } 77 | break; 78 | } 79 | } 80 | 81 | } 82 | 83 | #endif -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldb/util/win_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Logger implementation for Windows 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 8 | #define STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 9 | 10 | #include 11 | #include "leveldb/env.h" 12 | 13 | namespace leveldb { 14 | 15 | class WinLogger : public Logger { 16 | private: 17 | FILE* file_; 18 | public: 19 | explicit WinLogger(FILE* f) : file_(f) { assert(file_); } 20 | virtual ~WinLogger() { 21 | fclose(file_); 22 | } 23 | virtual void Logv(const char* format, va_list ap); 24 | 25 | }; 26 | 27 | } 28 | #endif // STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 29 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldbjni.cc: -------------------------------------------------------------------------------- 1 | #include "leveldbjni.h" 2 | 3 | extern int register_com_litl_leveldb_DB(JNIEnv *env); 4 | 5 | extern int register_com_litl_leveldb_WriteBatch(JNIEnv *env); 6 | 7 | extern int register_com_litl_leveldb_Iterator(JNIEnv *env); 8 | 9 | extern int register_com_litl_leveldb_Chunk(JNIEnv *env); 10 | 11 | jint 12 | throwException(JNIEnv *env, leveldb::Status status) { 13 | const char *exceptionClass; 14 | 15 | if (status.IsNotFound()) { 16 | exceptionClass = "com/litl/leveldb/NotFoundException"; 17 | } else if (status.IsCorruption()) { 18 | exceptionClass = "com/litl/leveldb/DatabaseCorruptException"; 19 | } else if (status.IsIOError()) { 20 | exceptionClass = "java/io/IOException"; 21 | } else { 22 | return 0; 23 | } 24 | 25 | jclass clazz = env->FindClass(exceptionClass); 26 | if (!clazz) { 27 | LOGE("Can't find exception class %s", exceptionClass); 28 | return -1; 29 | } 30 | 31 | return env->ThrowNew(clazz, status.ToString().c_str()); 32 | } 33 | 34 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { 35 | JNIEnv *env; 36 | if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { 37 | return -1; 38 | } 39 | 40 | register_com_litl_leveldb_DB(env); 41 | register_com_litl_leveldb_WriteBatch(env); 42 | register_com_litl_leveldb_Iterator(env); 43 | register_com_litl_leveldb_Chunk(env); 44 | 45 | return JNI_VERSION_1_6; 46 | } 47 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/leveldbjni.h: -------------------------------------------------------------------------------- 1 | #ifndef LEVELDBJNI_H_ 2 | #define LEVELDBJNI_H_ 3 | 4 | #include 5 | #include 6 | #include "leveldb/status.h" 7 | 8 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 9 | #define LOG_TAG "LevelDB" 10 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 11 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 12 | 13 | jint throwException(JNIEnv* env, leveldb::Status status); 14 | 15 | #endif /* LEVELDBJNI_H_ */ 16 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/mapkey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/3/27. 3 | // 4 | 5 | #ifndef CONVARTER_MAPKEY_H 6 | #define CONVARTER_MAPKEY_H 7 | 8 | #include 9 | 10 | typedef struct { 11 | int32_t x_div16; 12 | int32_t z_div16; 13 | int32_t dimension; 14 | } mapkey_t; 15 | 16 | #define LDBKEY_STRUCT(x, z, dim) mapkey_t{x >> 4, z >> 4, dim} 17 | 18 | #define LDBKEY_SUBCHUNK(k, ydiv) \ 19 | char key[14];\ 20 | if(true){\ 21 | char* ptr = key;\ 22 | *(int32_t*)ptr = k.x_div16;\ 23 | ptr+=4;\ 24 | *(int32_t*)ptr = k.z_div16;\ 25 | ptr += 4;\ 26 | if(k.dimension != 0){\ 27 | *(int32_t*)ptr = k.dimension;\ 28 | ptr += 4;\ 29 | }\ 30 | *ptr = 0x2f;\ 31 | ptr++;\ 32 | *ptr = ydiv;\ 33 | } 34 | 35 | #define LDBKEY_VERSION(k) \ 36 | char key_db[14];\ 37 | if(true){\ 38 | char* ptr = key_db;\ 39 | *(int32_t*)ptr = k.x_div16;\ 40 | ptr+=4;\ 41 | *(int32_t*)ptr = k.z_div16;\ 42 | ptr += 4;\ 43 | if(k.dimension != 0){\ 44 | *(int32_t*)ptr = k.dimension;\ 45 | ptr += 4;\ 46 | }\ 47 | *ptr = 0x76;\ 48 | ptr++;\ 49 | } 50 | 51 | #endif //CONVARTER_MAPKEY_H 52 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/qstr.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/3/24. 3 | // 4 | 5 | #ifndef CONVARTER_QSTR_H 6 | #define CONVARTER_QSTR_H 7 | 8 | typedef struct { 9 | unsigned int length; 10 | char *str; 11 | } qstr; 12 | 13 | typedef struct { 14 | unsigned int length; 15 | const char *str; 16 | } qcstr; 17 | 18 | typedef struct { 19 | unsigned int length; 20 | unsigned char *str; 21 | } qustr; 22 | 23 | #endif //CONVARTER_QSTR_H 24 | -------------------------------------------------------------------------------- /android-leveldb-master/library/src/main/jni/subchunk.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barco on 2018/12/24. 3 | // 4 | 5 | #ifndef CONVARTER_SUBCHUNK_H 6 | #define CONVARTER_SUBCHUNK_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define DEBUG_SUBCHUNK 13 | 14 | struct BlockStorage { 15 | uint8_t blen;//Length per block 16 | uint16_t types;//Types of blocks 17 | uint16_t *palette;//Palette 18 | uint32_t *storage;//Storage 19 | }; 20 | 21 | class SubChunk { 22 | private: 23 | 24 | static const int32_t msk[15]; 25 | 26 | static char pattern_name[10]; 27 | 28 | static char pattern_val[6]; 29 | 30 | BlockStorage storages[1]; 31 | 32 | const char *loadStorage(const char *ptr, const char *max, int which); 33 | 34 | uint16_t getBlockCode(unsigned char x, unsigned char y, unsigned char z, uint8_t which); 35 | 36 | public: 37 | SubChunk(const std::string &buf, bool hasMultiStorage); 38 | 39 | ~SubChunk(); 40 | 41 | uint16_t getBlock(unsigned char x, unsigned char y, unsigned char z); 42 | 43 | uint16_t 44 | getBlock3(unsigned char x, unsigned char y, unsigned char z, unsigned char layer); 45 | 46 | }; 47 | 48 | #endif //CONVARTER_SUBCHUNK_H 49 | -------------------------------------------------------------------------------- /android-leveldb-master/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library' 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 31 5 | defaultConfig { 6 | applicationId "com.tmsstudio.mappaintingeditor" 7 | minSdkVersion 23 8 | targetSdkVersion 31 9 | versionCode 1 10 | versionName "1.2.0" 11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 12 | // splits { 13 | // abi { 14 | // enable true 15 | // reset() 16 | // include 'x86', 'armeabi-v7a', 'x86_64' 17 | // universalApk true 18 | // } 19 | // } 20 | ndk { 21 | abiFilters 'armeabi-v7a', 'arm64-v8a' 22 | } 23 | } 24 | buildTypes { 25 | debug { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 28 | } 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | compileOptions { 35 | sourceCompatibility 1.8 36 | targetCompatibility 1.8 37 | } 38 | } 39 | 40 | dependencies { 41 | //include the android-leveldb library (see settings.gradle) 42 | implementation project(':android-leveldb-master') 43 | implementation fileTree(dir: 'libs', include: ['*.jar', '*.so']) 44 | implementation 'androidx.appcompat:appcompat:1.3.1' 45 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 46 | implementation 'androidx.recyclerview:recyclerview:1.2.1' 47 | implementation 'com.google.android.material:material:1.4.0' 48 | implementation 'io.reactivex.rxjava2:rxjava:2.2.21' 49 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' 50 | implementation 'com.guolindev.permissionx:permissionx:1.6.4' 51 | testImplementation 'junit:junit:4.13.2' 52 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 53 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 54 | } 55 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreatorMC/MapPaintingEditor/1145ec8fbf6fe03be9271ef4230ed59f18cbe890/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.2.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tmsstudio/mappaintingeditor/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor; 2 | 3 | import android.content.Context; 4 | import androidx.test.ext.junit.runners.AndroidJUnit4; 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * @see Testing documentation 15 | */ 16 | @RunWith(AndroidJUnit4.class) 17 | public class ExampleInstrumentedTest { 18 | @Test 19 | public void useAppContext() { 20 | // Context of the app under test. 21 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 22 | 23 | assertEquals("com.tmsstudio.mappaintingeditor", appContext.getPackageName()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/GridViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.LinearLayout; 11 | import android.widget.Toast; 12 | import androidx.activity.result.ActivityResultLauncher; 13 | import com.tmsstudio.mappaintingeditor.Message.Message; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * 包名: com.tmsstudio.mappaintingeditor 19 | * 日期: 2022/5/18 17:58 星期三 20 | * 工程: Map Painting Editor 21 | */ 22 | class GridViewAdapter extends BaseAdapter { 23 | private Context context; 24 | private ArrayList arrayList; 25 | private int row; 26 | private int col; 27 | 28 | private ActivityResultLauncher resultLauncher; 29 | 30 | public GridViewAdapter(Context context, ArrayList arrayList, int row, int col) { 31 | this.arrayList = arrayList; 32 | this.context = context; 33 | this.row = row; 34 | this.col = col; 35 | } 36 | 37 | @Override 38 | public int getCount() { 39 | return arrayList.size(); 40 | } 41 | 42 | @Override 43 | public Object getItem(int i) { 44 | return arrayList.get(i); 45 | } 46 | 47 | @Override 48 | public long getItemId(int i) { 49 | return i; 50 | } 51 | 52 | @Override 53 | public View getView(int i, View view, ViewGroup viewGroup) { 54 | ImageView imageView = new ImageView(context); 55 | imageView.setImageBitmap(arrayList.get(i)); 56 | imageView.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | if(((GridPicActivity) context).summon_ing){ 60 | Toast.makeText(context, "生成中,禁止操作", Toast.LENGTH_SHORT).show(); 61 | return; 62 | } 63 | //让用户从图库中选择图片 64 | Intent intent1 = new Intent(); 65 | intent1.setAction(Intent.ACTION_PICK); 66 | intent1.setType("image/*"); 67 | ((GridPicActivity) context).startActivityForResult(intent1, Message.EXTRA_MESSAGE_SELECT_PIC); 68 | } 69 | }); 70 | float dp = Util.pxToDp(128, context); 71 | float pic_size = 128; 72 | if(dp * row > 300.0){ //行数超过了控件大小 73 | pic_size = Util.dpToPx((float)(300.0 / row), context); 74 | } 75 | if(dp * col > 300.0){ 76 | pic_size = Util.dpToPx((float)(300.0 / col), context); 77 | } 78 | int size = (int)pic_size; 79 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size,size); 80 | imageView.setLayoutParams(params); 81 | 82 | return imageView; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/MapItem.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | public class MapItem { 6 | private Bitmap icon; 7 | private String name; 8 | private String path; 9 | private long size; 10 | private WorldType type; 11 | 12 | public MapItem(String name, String path, long size, WorldType type) { 13 | this.name = name; 14 | this.path = path; 15 | this.size = size; 16 | this.type = type; 17 | } 18 | 19 | public MapItem(Bitmap icon, String name, String path, long size, WorldType type) { 20 | this.icon = icon; 21 | this.name = name; 22 | this.path = path; 23 | this.size = size; 24 | this.type = type; 25 | } 26 | 27 | public Bitmap getIcon() { 28 | return icon; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public String getPath() { 36 | return path; 37 | } 38 | 39 | public long getSize() { 40 | return size; 41 | } 42 | 43 | public WorldType getType() { 44 | return type; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/Message/Message.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.Message; 2 | 3 | public class Message { 4 | public static final String EXTRA_MESSAGE_TO_ImportPicActivity = "com.tmsstudio.mappaintingeditor.ImportPicActivity"; 5 | public static final String EXTRA_MAPNAME_TO_ImportPicActivity = "com.tmsstudio.mappaintingeditor.map_name.ImportPicActivity"; 6 | public static final String EXTRA_MESSAGE_TO_MAINSELECT = "com.tmsstudio.mappaintingeditor.map_name.MainSelectActivity"; 7 | // public static final String EXTRA_MAPNAME_TO_NAME = "com.tmsstudio.mappaintingeditor.map_name.NAME"; 8 | // public static final String EXTRA_MAPVERSION_TO_VERSION = "com.tmsstudio.mappaintingeditor.map_name.VERSION"; 9 | public static final int EXTRA_MESSAGE_SELECT_PIC = 233; 10 | public static final int REQUEST_EMPOWER = 5; 11 | public static final int SELECT_MAP_FINISH = 42569; 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/TransitionActivity.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | import com.tmsstudio.mappaintingeditor.Message.Message; 8 | 9 | public class TransitionActivity extends AppCompatActivity { 10 | 11 | String folder; //地图根文件夹路径 12 | // ArrayList arrayListName; 13 | String name; //地图名称 14 | // int version; 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_transition); 20 | 21 | final Intent intent = getIntent(); 22 | folder = intent.getStringExtra(Message.EXTRA_MESSAGE_TO_ImportPicActivity); 23 | name = intent.getStringExtra(Message.EXTRA_MAPNAME_TO_ImportPicActivity); 24 | this.setTitle(name); 25 | } 26 | 27 | public void chooseNormal(View view) { 28 | //跳转到普通模式 29 | Intent intent = new Intent(view.getContext(), ImportPicActivity.class); 30 | intent.putExtra(Message.EXTRA_MESSAGE_TO_ImportPicActivity, folder); 31 | intent.putExtra(Message.EXTRA_MAPNAME_TO_ImportPicActivity, name); 32 | startActivity(intent); 33 | } 34 | 35 | public void chooseGrid(View view) { 36 | //跳转到网格模式 37 | Intent intent = new Intent(view.getContext(), GridPicActivity.class); 38 | intent.putExtra(Message.EXTRA_MESSAGE_TO_ImportPicActivity, folder); 39 | intent.putExtra(Message.EXTRA_MAPNAME_TO_ImportPicActivity, name); 40 | startActivity(intent); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/WorldType.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor; 2 | 3 | /** 4 | * 包名: com.tmsstudio.mappaintingeditor 5 | * 日期: 2022/5/18 14:23 星期三 6 | * 工程: Map Painting Editor 7 | */ 8 | public enum WorldType { 9 | Unknown, OutdatedBedrock, Bedrock, NetEaseBedrock 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/EditableNBT.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.tags.Tag; 4 | 5 | /** 6 | * Wrapper around NBT data for easy passing and saving without knowing its context. 7 | */ 8 | public abstract class EditableNBT { 9 | 10 | boolean modified = false; 11 | 12 | public boolean enableRootModifications = true; 13 | 14 | public abstract Iterable getTags(); 15 | 16 | public void setModified(){ 17 | modified = true; 18 | } 19 | 20 | public boolean isModified(){ return modified; } 21 | 22 | /** 23 | * Save the NBT data to something. 24 | * 25 | * @return if the save was successful 26 | */ 27 | public abstract boolean save(); 28 | 29 | 30 | public abstract String getRootTitle(); 31 | 32 | 33 | public abstract void addRootTag(Tag tag); 34 | 35 | public abstract void removeRootTag(Tag tag); 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/Keys.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt; 2 | 3 | public final class Keys { 4 | 5 | public static final String LEVEL_NAME = "LevelName"; 6 | public static final String LOCAL_PLAYER = "~local_player"; 7 | public static final String FLAT_WORLD_LAYERS = "FlatWorldLayers"; 8 | public static final String LAST_PLAYED = "LastPlayed"; 9 | public static final String INVENTORY = "Inventory"; 10 | public static final String INV_NAME = "Name"; 11 | public static final String INV_ID = "id"; 12 | public static final String INV_DAMAGE = "Damage"; 13 | public static final String INV_COUNT = "Count"; 14 | public static final String INV_SLOT = "Slot"; 15 | public static final String INV_TAG = "tag"; 16 | public static final String I_BOOK_AUTHOR = "author"; 17 | public static final String I_BOOK_GENERATION = "generation"; 18 | public static final String I_BOOK_ID = "id"; 19 | public static final String I_BOOK_PAGES = "pages"; 20 | public static final String I_BOOK_TITLE = "title"; 21 | public static final String I_BOOK_XUID = "xuid"; 22 | public static final String I_BOOK_PAGES_PHOTONAME = "photoname"; 23 | public static final String I_BOOK_PAGES_TEXT = "text"; 24 | public static final String I_BOOK_PAGES_CLICK = "clickEvent"; 25 | public static final String I_BOOK_PAGES_CLICK_ACTION = "action"; 26 | public static final String I_BOOK_PAGES_CLICK_ACTION_URL = "open_url"; 27 | public static final String I_BOOK_PAGES_CLICK_VALUE = "value"; 28 | 29 | //public static final String =""; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/convert/DataConverter.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.convert; 2 | 3 | 4 | import com.tmsstudio.mappaintingeditor.nbt.tags.Tag; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | 13 | public class DataConverter { 14 | 15 | public static ArrayList read(byte[] input) throws IOException { 16 | ByteArrayInputStream bais = new ByteArrayInputStream(input); 17 | NBTInputStream in = new NBTInputStream(bais); 18 | ArrayList tags = in.readTopLevelTags(); 19 | in.close(); 20 | return tags; 21 | 22 | } 23 | 24 | public static byte[] write(List tags) throws IOException { 25 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 26 | NBTOutputStream out = new NBTOutputStream(bos); 27 | for (Tag tag : tags) { 28 | out.writeTag(tag); 29 | } 30 | out.close(); 31 | return bos.toByteArray(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/convert/LevelDataConverter.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.convert; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.tags.CompoundTag; 4 | 5 | import java.io.*; 6 | 7 | public final class LevelDataConverter { 8 | 9 | public static final byte[] header = {0x04, 0x00, 0x00, 0x00}; 10 | 11 | public static CompoundTag read(InputStream inputStream) throws IOException { 12 | skip(inputStream, 8); 13 | // Skip the length? Yeah I know it's redundant but... 14 | NBTInputStream in = new NBTInputStream(inputStream); 15 | CompoundTag levelTag = (CompoundTag) in.readTag(); 16 | in.close(); 17 | return levelTag; 18 | } 19 | 20 | public static CompoundTag read(File file) throws IOException { 21 | FileInputStream fis = new FileInputStream(file); 22 | BufferedInputStream is = new BufferedInputStream(fis); 23 | skip(is, 8); 24 | NBTInputStream in = new NBTInputStream(is); 25 | CompoundTag levelTag = (CompoundTag) in.readTag(); 26 | in.close(); 27 | return levelTag; 28 | } 29 | 30 | public static void write(CompoundTag levelTag, File file) throws IOException { 31 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 32 | NBTOutputStream out = new NBTOutputStream(bos); 33 | out.writeTag(levelTag); 34 | out.close(); 35 | FileOutputStream os = new FileOutputStream(file); 36 | DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(os)); 37 | int length = bos.size(); 38 | dos.write(header); 39 | dos.writeInt(Integer.reverseBytes(length)); 40 | bos.writeTo(dos); 41 | dos.close(); 42 | } 43 | 44 | /** 45 | * source: http://stackoverflow.com/questions/14057720/robust-skipping-of-data-in-a-java-io-inputstream-and-its-subtypes 46 | *

47 | * Skips n bytes. 48 | */ 49 | public static void skip(InputStream is, long n) throws IOException { 50 | while (n > 0) { 51 | long n1 = is.skip(n); 52 | if (n1 > 0) { 53 | n -= n1; 54 | } else if (n1 == 0) { // should we retry? lets read one byte 55 | if (is.read() == -1) // EOF 56 | break; 57 | else 58 | n--; 59 | } else // negative? this should never happen but... 60 | throw new IOException("skip() returned a negative value - this should never happen"); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/ByteArrayTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class ByteArrayTag extends Tag { 6 | 7 | private static final long serialVersionUID = 5667709255740878805L; 8 | 9 | public ByteArrayTag(String name, byte[] value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.BYTE_ARRAY; 16 | } 17 | 18 | @Override 19 | public Tag getDeepCopy() { 20 | return new ByteArrayTag(name, value.clone()); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/ByteTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class ByteTag extends Tag { 6 | 7 | private static final long serialVersionUID = -8072877139532366356L; 8 | 9 | public ByteTag(String name, byte value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.BYTE; 16 | } 17 | 18 | @Override 19 | public ByteTag getDeepCopy() { 20 | return new ByteTag(name, value); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/CompoundTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class CompoundTag extends Tag> { 9 | 10 | private static final long serialVersionUID = 4540757946052775740L; 11 | 12 | public CompoundTag(String name, ArrayList value) { 13 | super(name, value); 14 | } 15 | 16 | @Override 17 | public NBTConstants.NBTType getType() { 18 | return NBTConstants.NBTType.COMPOUND; 19 | } 20 | 21 | 22 | public Tag getChildTagByKey(String key){ 23 | List list = getValue(); 24 | if(list == null) return null; 25 | for(Tag tag : list){ 26 | if(key.equals(tag.getName())) return tag; 27 | } 28 | return null; 29 | } 30 | 31 | public String toString(){ 32 | String name = getName(); 33 | String type = getType().name(); 34 | ArrayList value = getValue(); 35 | StringBuilder bldr = new StringBuilder(); 36 | bldr.append(type == null ? "?" : ("TAG_" + type)) 37 | .append(name == null ? "(?)" : ("(" + name + ")")); 38 | 39 | if(value != null) { 40 | bldr.append(": ") 41 | .append(value.size()) 42 | .append(" entries\n{\n"); 43 | for (Tag entry : value) { 44 | //pad every line of the value 45 | bldr.append(" ") 46 | .append(entry.toString().replaceAll("\n", "\n ")) 47 | .append("\n"); 48 | } 49 | bldr.append("}"); 50 | 51 | } else bldr.append(":?"); 52 | 53 | return bldr.toString(); 54 | } 55 | 56 | @Override 57 | public CompoundTag getDeepCopy() { 58 | if(value != null){ 59 | ArrayList copy = new ArrayList<>(); 60 | for(Tag tag : value){ 61 | copy.add(tag.getDeepCopy()); 62 | } 63 | return new CompoundTag(name, copy); 64 | } else return new CompoundTag(name, null); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/DoubleTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class DoubleTag extends Tag { 6 | 7 | private static final long serialVersionUID = 2230008080333021410L; 8 | 9 | public DoubleTag(String name, double value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.DOUBLE; 16 | } 17 | 18 | @Override 19 | public DoubleTag getDeepCopy() { 20 | return new DoubleTag(name, value); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/EndTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class EndTag extends Tag { 6 | 7 | private static final long serialVersionUID = 1654129404501308744L; 8 | 9 | public EndTag() { 10 | super("", null); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.END; 16 | } 17 | 18 | @Override 19 | public EndTag getDeepCopy() { 20 | return new EndTag(); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/FloatTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class FloatTag extends Tag { 6 | 7 | private static final long serialVersionUID = -1566271877968979568L; 8 | 9 | public FloatTag(String name, float value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.FLOAT; 16 | } 17 | 18 | @Override 19 | public FloatTag getDeepCopy() { 20 | return new FloatTag(name, value); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/IntArrayTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class IntArrayTag extends Tag { 6 | 7 | private static final long serialVersionUID = 827586678981022917L; 8 | 9 | public IntArrayTag(String name, int[] value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.INT_ARRAY; 16 | } 17 | 18 | @Override 19 | public Tag getDeepCopy() { 20 | return new IntArrayTag(name, value.clone()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/IntTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class IntTag extends Tag { 6 | 7 | private static final long serialVersionUID = -4390371124151508132L; 8 | 9 | public IntTag(String name, int value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.INT; 16 | } 17 | 18 | @Override 19 | public IntTag getDeepCopy() { 20 | return new IntTag(name, value); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/ListTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class ListTag extends Tag> { 8 | 9 | 10 | private static final long serialVersionUID = -4765717626522070446L; 11 | 12 | public ListTag(String name, ArrayList value) { 13 | super(name, value); 14 | } 15 | 16 | @Override 17 | public NBTConstants.NBTType getType() { 18 | return NBTConstants.NBTType.LIST; 19 | } 20 | 21 | 22 | public String toString(){ 23 | String name = getName(); 24 | String type = getType().name(); 25 | ArrayList value = getValue(); 26 | StringBuilder bldr = new StringBuilder(); 27 | bldr.append(type == null ? "?" : ("TAG_" + type)) 28 | .append(name == null ? "(?)" : ("(" + name + ")")); 29 | 30 | if(value != null) { 31 | bldr.append(": ") 32 | .append(value.size()) 33 | .append(" entries\n[\n"); 34 | for (Tag entry : value) { 35 | //pad every line of the value 36 | bldr.append(" ") 37 | .append(entry.toString().replaceAll("\n", "\n ")) 38 | .append("\n"); 39 | } 40 | bldr.append("]"); 41 | } else bldr.append(":?"); 42 | 43 | return bldr.toString(); 44 | } 45 | 46 | 47 | @Override 48 | public ListTag getDeepCopy() { 49 | if(value != null){ 50 | ArrayList copy = new ArrayList<>(); 51 | for(Tag tag : value){ 52 | copy.add(tag.getDeepCopy()); 53 | } 54 | return new ListTag(name, copy); 55 | } else return new ListTag(name, null); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/LongTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class LongTag extends Tag { 6 | 7 | private static final long serialVersionUID = 1571527153983268515L; 8 | 9 | public LongTag(String name, long value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.LONG; 16 | } 17 | 18 | @Override 19 | public LongTag getDeepCopy() { 20 | return new LongTag(name, value); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/ShortArrayTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class ShortArrayTag extends Tag { 6 | 7 | private static final long serialVersionUID = -7722759532672413660L; 8 | 9 | public ShortArrayTag(String name, short[] value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.SHORT_ARRAY; 16 | } 17 | 18 | @Override 19 | public Tag getDeepCopy() { 20 | return new ShortArrayTag(name, value.clone()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/ShortTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class ShortTag extends Tag { 6 | 7 | private static final long serialVersionUID = 8478629669505321780L; 8 | 9 | public ShortTag(String name, short value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.SHORT; 16 | } 17 | 18 | 19 | @Override 20 | public ShortTag getDeepCopy() { 21 | return new ShortTag(name, value); 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/java/com/tmsstudio/mappaintingeditor/nbt/tags/StringTag.java: -------------------------------------------------------------------------------- 1 | package com.tmsstudio.mappaintingeditor.nbt.tags; 2 | 3 | import com.tmsstudio.mappaintingeditor.nbt.convert.NBTConstants; 4 | 5 | public class StringTag extends Tag { 6 | 7 | private static final long serialVersionUID = 9167318877259218937L; 8 | 9 | public StringTag(String name, String value) { 10 | super(name, value); 11 | } 12 | 13 | @Override 14 | public NBTConstants.NBTType getType() { 15 | return NBTConstants.NBTType.STRING; 16 | } 17 | 18 | 19 | @Override 20 | public StringTag getDeepCopy() { 21 | return new StringTag(name, value); 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_drop_up_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/linearlayout_underline.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity11_main_select.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_expand_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 24 | 25 | 34 | 35 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_help.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_map_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 24 | 25 | 39 | 40 | 53 | 54 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_transition.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 17 | 18 |