{"id":16526730,"url":"https://github.com/tetraquark/myersdiffkt","last_synced_at":"2025-09-11T23:33:11.452Z","repository":{"id":194402327,"uuid":"241642224","full_name":"Tetraquark/MyersDiffKt","owner":"Tetraquark","description":"Kotlin Multiplatform library implements Myers algorithm for diff calculations.","archived":false,"fork":false,"pushed_at":"2020-08-23T14:56:08.000Z","size":148,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T13:35:29.560Z","etag":null,"topics":["diff","diff-calculations","kotlin","kotlin-multiplatform","kotlin-multiplatform-library","myers-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tetraquark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-02-19T14:27:52.000Z","updated_at":"2023-03-06T19:01:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"a21c42f2-852b-4206-a726-efdeeb753593","html_url":"https://github.com/Tetraquark/MyersDiffKt","commit_stats":null,"previous_names":["tetraquark/myersdiffkt"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tetraquark%2FMyersDiffKt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tetraquark%2FMyersDiffKt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tetraquark%2FMyersDiffKt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tetraquark%2FMyersDiffKt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tetraquark","download_url":"https://codeload.github.com/Tetraquark/MyersDiffKt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238623790,"owners_count":19503103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","diff-calculations","kotlin","kotlin-multiplatform","kotlin-multiplatform-library","myers-algorithm"],"created_at":"2024-10-11T17:29:47.803Z","updated_at":"2025-02-13T08:33:27.745Z","avatar_url":"https://github.com/Tetraquark.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## MyersDiffKt\n\n[ ![Download](https://api.bintray.com/packages/tetraquark/kmplibs/MyersDiffKt/images/download.svg) ](https://bintray.com/tetraquark/kmplibs/MyersDiffKt/_latestVersion)\n\nKotlin Multiplatform library implements iterative Myers algorithm for diff calculations without the second pass for moves detection.\n\nThe algorithm is implemented in common source set, so it can be used in any supported platform.\n\nThe main part of the algorithm implementation is rewritten to Kotlin from the Android Java library - [DiffUtil](https://developer.android.com/reference/android/support/v7/util/DiffUtil).\n\n### Versions\n\nLibrary version | Kotlin version\n------------ | -------------\n1.2.0 | 1.4.0\n1.1.0 | 1.3.72\n1.0.0 | 1.3.61\n\n## Setup\n\nIn root **build.gradle.kts** add the maven repository url:\n\n```kotlin\nallprojects {\n    repositories {\n        maven { url = uri(\"https://dl.bintray.com/tetraquark/kmplibs\") }\n    }\n}\n```\n\nor in root **build.gradle**\n```groovy\nallprojects {\n    repositories {\n        maven { url \"https://dl.bintray.com/tetraquark/kmplibs\" }\n    }\n}\n```\n\nThen in a project **build.gradle.kts**:\n```kotlin\ndependencies {\n    implementation(\"ru.tetraquark.kmplibs:MyersDiffKt:1.2.0\")\n}\n```\n\nor in a project **build.gradle**:\n\n```groovy\ndependencies {\n    implementation \"ru.tetraquark.kmplibs:MyersDiffKt:1.2.0\"\n}\n```\n\n## Usage\n\nTo calculate difference for two lists, use `DiffUtil` singleton object. There are two public functions:\n\n```kotlin\nsuspend fun diffFlow(\n    oldListSize: Int,\n    newListSize: Int,\n    comparator: (oldItemIndex: Int, newItemIndex: Int) -\u003e Boolean\n): Flow\u003cChange\u003e\n```\n\n```kotlin\nfun diffCallback(\n    oldListSize: Int,\n    newListSize: Int,\n    comparator: (oldItemIndex: Int, newItemIndex: Int) -\u003e Boolean\n): DiffResult\n```\n\n`diffFlow` function is suspendable and returns `Flow` instance, so difference calculations can be implemented in asynchronus style using Kotlin coroutines.\n\n`diffCallback` function returns `DiffResult` object that holds a calculation results.\n\nUse example for `diffFlow` function:\n\n```kotlin\nlaunch {\n    DiffUtil.diffFlow(oldList.size, newList.size) { oldItemIndex, newItemIndex -\u003e\n        oldList[oldItemIndex] == newList[newItemIndex]\n    }\n    .flowOn(Dispatchers.Default)\n    .collect { change -\u003e\n        applyChangeToLists(resultList, newList, change)\n    }\n}\n```\n\nThere is simple example of Android application in **sample-android** module that uses the library to calculating and applying differences for RecyclerView content.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetraquark%2Fmyersdiffkt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftetraquark%2Fmyersdiffkt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetraquark%2Fmyersdiffkt/lists"}