CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 14:11:02 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=88c20c4fde2c614a3dad7c8544ad62083ff02dadd90656db1f70ab1e4ac24efda%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22lLZuMbb9g04clzlbLWCpTCoHC1WZKpqq%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cef1c458d1999b-BLR
PriorityStack - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.collection.mutable
- trait PriorityStack[Elem] {
- def pop(): Option[Elem]
- def push(elem: Elem): Unit
- }
- object PriorityStack {
- private class Impl[Elem: Ordering](
- initialCapacity: Int,
- capacityFactor: Float,
- ) extends PriorityStack[Elem] {
- private val ordering: Ordering[AnyRef] = new Ordering[AnyRef] {
- override def compare(x: AnyRef, y: AnyRef): Int =
- (x, y) match {
- case (null, _) => 1
- case (_, null) => -1
- case (null, null) => 0
- case _ => Ordering[Elem].compare(
- x.asInstanceOf[Elem],
- y.asInstanceOf[Elem],
- )
- }
- }
- private var underlying = new Array[AnyRef](initialCapacity)
- private var last = -1
- override def pop(): Option[Elem] =
- if(last > 0) {
- def shrink(): Unit = {
- val needShrink = (last * capacityFactor).toInt < underlying.length
- if (needShrink) {
- val shrinked = new Array[AnyRef](last)
- Array.copy(
- src = underlying,
- srcPos = 0,
- dest = shrinked,
- destPos = 0,
- length = last,
- )
- }
- }
- def head(): Option[Elem] = {
- val take = last
- last -= 1
- val elem = underlying(take).asInstanceOf[Elem]
- underlying(take) = null.asInstanceOf[AnyRef]
- Some(elem)
- }
- shrink()
- head()
- } else {
- None
- }
- override def push(elem: Elem): Unit = {
- def grow(): Unit = {
- val current = last + 1
- if(current > underlying.length) {
- val size = (current * capacityFactor).toInt
- val growed = new Array[AnyRef](size)
- Array.copy(
- src = underlying,
- srcPos = 0,
- dest = growed,
- destPos = 0,
- length = last,
- )
- underlying = growed
- }
- last = current
- }
- def insert(): Unit = {
- underlying(last) = elem.asInstanceOf[AnyRef]
- underlying.sortInPlace()(ordering)
- }
- grow()
- insert()
- }
- override def toString(): String =
- underlying.mkString("PriorityStack(", ", ", ")")
- }
- def apply[Elem: Ordering](initialCapacity: Int = 16,
- growFactor: Float = 2f): PriorityStack[Elem] =
- new Impl[Elem](initialCapacity, growFactor)
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Jack's Profit Method ✅ NEVER SEEN BEF...
JavaScript | 5 sec ago | 0.24 KB
-
⭐⭐⭐Exploit 500$ in 15 Minutes⭐⭐
Java | 7 sec ago | 0.10 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 4
JavaScript | 10 sec ago | 0.24 KB
-
⭐✅ Online Marketplace Exploit ✅ NEVER SEEN BE...
JavaScript | 15 sec ago | 0.24 KB
-
⭐⭐⭐Exploit 500$ in 15 Minutes⭐⭐
Java | 18 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ C
JavaScript | 21 sec ago | 0.24 KB
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 24 sec ago | 0.24 KB
-
⭐⭐⭐MAKE $9OO INSTANTLY D M⭐⭐
Java | 29 sec ago | 0.10 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand