Last active
October 9, 2022 11:32
-
-
Save sebkraemer/ae2b3cdad8d92f67be6df30685c20e1b to your computer and use it in GitHub Desktop.
mic lower_bound
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:collection/collection.dart'; | |
class Mitarbeiter { | |
int gehalt; | |
String name; | |
Mitarbeiter(this.gehalt, this.name); | |
} | |
int micLowerBound<E, V>(List<E> sortedList, V value, {int compare(E, V)?}) { | |
if (compare == null) { | |
return 0; // todo call standard compare | |
} else { | |
return compare(sortedList.first, value); // todo implement lower_bound properly | |
} | |
} | |
void runLowerBounds() { | |
var mList = [Mitarbeiter(50000, "karl"), Mitarbeiter(100000, "boss")]; | |
var m3 = Mitarbeiter(65000, "lenny"); | |
var i = mList.lowerBound(m3, (p0, p1) => p0.gehalt - p1.gehalt); | |
// : Invalid argument: Instance of '_Type'Error: Invalid argument: Instance of '_Type' | |
var i2 = micLowerBound(mList, 65000, | |
compare: (mitarbeiter, gehalt) => mitarbeiter.gehalt - gehalt); | |
print('lowerBound: $i'); | |
print('lowerBoundBy: $i2'); | |
} | |
void main() { | |
runLowerBounds(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The gist shows how a lower_bound could be implemented that does not need to create an object of type E just for comparison.