Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Convert ArrayMap to collections.abc #4

Closed
nedtwigg opened this issue Feb 20, 2024 · 3 comments
Closed

Convert ArrayMap to collections.abc #4

nedtwigg opened this issue Feb 20, 2024 · 3 comments
Assignees

Comments

@nedtwigg
Copy link
Member

Selfie has a few generic data structures that we use in lots of places. In order of complexity, they are:

abstract class ListBackedSet<T>() : AbstractSet<T>() {

/**
* An immutable, sorted, array-backed set - if keys are [String], they have a special sort order
* where `/` is the lowest key.
*/
class ArraySet<K : Comparable<K>>(private val data: Array<Any>) : ListBackedSet<K>() {

/**
* An immutable, sorted, array-backed map - if keys are [String], they have a special sort order
* where `/` is the lowest key.
*/
class ArrayMap<K : Comparable<K>, V : Any>(private val data: Array<Any>) : Map<K, V> {

We should implement them in Python using the collections.abc framework.

  • ListBackedSet should extend Set and Sequence
  • ArrayMap should extend Mapping

We have a few tests for these here, but there should be more.

https://github.com/diffplug/selfie-python-wip/blob/main/jvm/selfie-lib/src/commonTest/kotlin/com/diffplug/selfie/ArrayMapTest.kt

I think using PEP 695 will make the rest of this easier, but it's not a hard requirement.

Here's an example conversation with ChatGPT for going about this task.

@nedtwigg
Copy link
Member Author

@nedtwigg
Copy link
Member Author

nedtwigg commented Mar 4, 2024

  • Mostly completed by ArrayMap.py #17
  • Remaining issues for the medium-term future
    • special sort order for strings
    • use binary search, never linear search

@nedtwigg
Copy link
Member Author

nedtwigg commented Apr 2, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants