repo for my hex addons :3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

insertion-ordered maps & rearrange map docs

+52 -36
+4 -2
build.gradle.kts
··· 232 232 exactRepo("https://maven.ladysnake.org/releases/", 233 233 "dev.onyxstudios") 234 234 exactRepo("https://pool.net.eu.org/", 235 + "com.unascribed", 235 236 "dev.kineticcat.hexportation", 236 237 "miyucomics.hexcellular", 237 238 "miyucomics.hexical", ··· 245 246 exactRepo("https://maven.terraformersmc.com/releases", 246 247 "com.terraformersmc", 247 248 "dev.emi") 248 - exactRepo("https://repo.sleeping.town/", 249 - "com.unascribed") 249 + // mirrored by poolmaven due to invalid cert 250 + //exactRepo("https://repo.sleeping.town/", 251 + // "com.unascribed") 250 252 exactRepo("https://masa.dy.fi/maven/", 251 253 "carpet") 252 254 exactRepo("https://maven.nucleoid.xyz/",
+2
util/changelog
··· 1 1 0.1.2 add portals 2 + 0.1.2 documented Flock's Disintegration and Speaker's Distillation for maps 2 3 0.1.2 intrusive holder allocation tracking 4 + 0.1.2 made maps insertion-ordered
+36 -20
util/src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us/entries/addon/phlib/maps.json
··· 15 15 }, 16 16 { 17 17 "type": "hexcasting:pattern", 18 - "op_id": "hexcasting:add", 19 - "anchor": "hexcasting:add", 20 - "input": "map<k, v>, map<k, v>", 18 + "op_id": "hexcasting:replace", 19 + "anchor": "hexcasting:replace", 20 + "input": "map<k, v>, k, v", 21 21 "output": "map<k, v>", 22 - "text": "Merges two maps together. Maps cannot have duplicate items: any entry in the latter map will override that in the first map." 22 + "text": "Replaces the element associated with $(n)k/$ with $(n)v/$. If $(n)k/$ is not present in the map, the entry is created and placed at the end of the map." 23 23 }, 24 24 { 25 25 "type": "hexcasting:pattern", 26 - "op_id": "hexcasting:sub", 27 - "anchor": "hexcasting:sub", 28 - "input": "map<k, v>, map<t, *>", 26 + "op_id": "hexcasting:remove_from", 27 + "anchor": "hexcasting:remove_from", 28 + "input": "map<k, v>, k", 29 29 "output": "map<k, v>", 30 - "text": "Removes every entry in the first map that is found in the second map. The values in the second map are ignored." 30 + "text": "Throws out the map's association for the given key. If there is no matching association, the map is returned unchanged." 31 31 }, 32 32 { 33 33 "type": "hexcasting:pattern", ··· 35 35 "anchor": "hexcasting:index", 36 36 "input": "map<k, v>, k", 37 37 "output": "v?", 38 - "text": "Disintegrates the map, returning only the value associated with the given key. O(1), unlike scanning a list." 38 + "text": "Destroys the map, returning only the value associated with the given key. O(1), unlike scanning a list." 39 + }, 40 + { 41 + "type": "hexcasting:pattern", 42 + "op_id": "hexcasting:splat", 43 + "anchor": "hexcasting:splat", 44 + "input": "map<k, v>", 45 + "output": "k, v, k, v...", 46 + "text": "Disintegrates the map, returning the key-value pairs in the order I inserted them." 39 47 }, 40 48 { 41 49 "type": "hexcasting:pattern", 42 50 "op_id": "hexcasting:unappend", 43 51 "anchor": "hexcasting:unappend", 44 - "input": "map<k, v>", 45 - "output": "map<k, v>, (k, v)?", 46 - "text": "Shaves off one element of a map. Which element gets shaved off is undefined and subject to Nature's whims. If used on an empty map, returns two nulls." 52 + "input": "map<k,v>", 53 + "output": "map<k,v>, (k,v | nulls)", 54 + "text": "Shaves off the element I added most recently from a map. If used on an empty map, returns two nulls." 47 55 }, 48 56 { 49 57 "type": "hexcasting:pattern", 50 - "op_id": "hexcasting:replace", 51 - "anchor": "hexcasting:replace", 52 - "input": "map<k, v>, k, v", 58 + "op_id": "hexcasting:deconstruct", 59 + "anchor": "hexcasting:deconstruct", 60 + "input": "map<k,v>", 61 + "output": "map<k,v>, (k,v | nulls)", 62 + "text": "Shaves off the element I added least recently from a map. If used on an empty map, returns two nulls." 63 + }, 64 + { 65 + "type": "hexcasting:pattern", 66 + "op_id": "hexcasting:add", 67 + "anchor": "hexcasting:add", 68 + "input": "map<k, v>, map<k, v>", 53 69 "output": "map<k, v>", 54 - "text": "Replaces the element associated with $(n)k/$ with $(n)v/$. If $(n)k/$ is not present in the map, the entry is created." 70 + "text": "Merges two maps together. Maps cannot have duplicate items: any entry in the latter map will override that in the first map." 55 71 }, 56 72 { 57 73 "type": "hexcasting:pattern", 58 - "op_id": "hexcasting:remove_from", 59 - "anchor": "hexcasting:remove_from", 60 - "input": "map<k, v>, k", 74 + "op_id": "hexcasting:sub", 75 + "anchor": "hexcasting:sub", 76 + "input": "map<k, v>, map<t, *>", 61 77 "output": "map<k, v>", 62 - "text": "Throws out the map's association for the given key. If there is no matching association, the map is returned unchanged." 78 + "text": "Removes every entry in the first map that is found in the second map. The values in the second map are ignored." 63 79 } 64 80 ] 65 81 }
+10 -14
util/src/main/scala/org/eu/net/pool/phlib/maps.scala
··· 11 11 import net.minecraft.text.{MutableText, Text} 12 12 import net.minecraft.util.Formatting 13 13 14 + import java.util 14 15 import java.util.List => JavaList 16 + import scala.collection.immutable.ListMap 15 17 import net.minecraft.server.world.ServerWorld 16 18 import at.petrak.hexcasting.api.utils.HexUtils 17 19 18 - case class MapIota(map: Map[NbtCompound, NbtCompound] = Map(), trusted: Boolean = false)(using val world: ServerWorld) extends Iota(MapIota, map): 20 + case class MapIota(map: Map[NbtCompound, NbtCompound] = ListMap())(using val world: ServerWorld) extends Iota(MapIota, map): 19 21 def get(key: Iota): Option[Iota] = map.get(IotaType.serialize(key)).map(IotaType.deserialize(_, summon)) 20 22 def apply(key: Iota): Iota = get(key) getOrElse NullIota() 21 23 def -(keys: Iota*): MapIota = MapIota(map -- (keys map IotaType.serialize)) ··· 45 47 c.put("k", p._1) 46 48 c.put("v", p._2)) tap l.add) 47 49 override def size = map.toSeq.map(_.size + _.size - 1).sum + 1 48 - override def subIotas(): java.lang.Iterable[Iota] = 49 - if trusted then 50 - // skip deserialization for performance 51 - // this is safe because `trusted` can only be true if truenames have 52 - // already been checked, and we override `size` 53 - Seq() 54 - else 55 - toList 56 - def asJavaMap: java.util.Map[Iota, Iota] = map.map(e => (IotaType.deserialize(e._1, summon), IotaType.deserialize(e._2, summon))).toMap 50 + override def subIotas(): java.lang.Iterable[Iota] = toList 51 + def asJavaMap: java.util.Map[Iota, Iota] = 52 + val ret = util.LinkedHashMap[Iota, Iota]() 53 + for k -> v <- map do 54 + ret(IotaType.deserialize(k, summon)) = IotaType.deserialize(v, summon) 55 + ret 57 56 object MapIota extends IotaType[MapIota]: 58 57 def color: Int = 0xb0641c 59 58 def deserialize(using data: NbtElement, world: ServerWorld): MapIota = 60 59 val l = HexUtils.downcast(data, NbtList.TYPE) 61 60 val o = HexUtils.downcast(_, NbtCompound.TYPE) 62 - l.map(o) 63 - .map(c => (o(c("k")), o(c("v")))) 64 - .toMap[NbtCompound, NbtCompound] 65 - .pipe(new MapIota(_, trusted = true)) 61 + new MapIota(ListMap.from(l.map(o).map(c => (o(c("k")), o(c("v")))))) 66 62 def display(data: NbtElement): Text = 67 63 val items = HexUtils.downcast(data, NbtList.TYPE) 68 64 val output: MutableText = "["