ADD week 5

This commit is contained in:
2025-03-31 16:33:42 +02:00
parent 86f265f22d
commit bf645048e6
4927 changed files with 544053 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,122 @@
package androidx.coordinatorlayout.widget;
import androidx.collection.SimpleArrayMap;
import androidx.core.util.Pools;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/* loaded from: classes.dex */
public final class DirectedAcyclicGraph<T> {
private final Pools.Pool<ArrayList<T>> mListPool = new Pools.SimplePool(10);
private final SimpleArrayMap<T, ArrayList<T>> mGraph = new SimpleArrayMap<>();
private final ArrayList<T> mSortResult = new ArrayList<>();
private final HashSet<T> mSortTmpMarked = new HashSet<>();
public void addNode(T t) {
if (this.mGraph.containsKey(t)) {
return;
}
this.mGraph.put(t, null);
}
public boolean contains(T t) {
return this.mGraph.containsKey(t);
}
public void addEdge(T t, T t2) {
if (!this.mGraph.containsKey(t) || !this.mGraph.containsKey(t2)) {
throw new IllegalArgumentException("All nodes must be present in the graph before being added as an edge");
}
ArrayList<T> arrayList = this.mGraph.get(t);
if (arrayList == null) {
arrayList = getEmptyList();
this.mGraph.put(t, arrayList);
}
arrayList.add(t2);
}
public List getIncomingEdges(T t) {
return this.mGraph.get(t);
}
public List<T> getOutgoingEdges(T t) {
int size = this.mGraph.size();
ArrayList arrayList = null;
for (int i = 0; i < size; i++) {
ArrayList<T> valueAt = this.mGraph.valueAt(i);
if (valueAt != null && valueAt.contains(t)) {
if (arrayList == null) {
arrayList = new ArrayList();
}
arrayList.add(this.mGraph.keyAt(i));
}
}
return arrayList;
}
public boolean hasOutgoingEdges(T t) {
int size = this.mGraph.size();
for (int i = 0; i < size; i++) {
ArrayList<T> valueAt = this.mGraph.valueAt(i);
if (valueAt != null && valueAt.contains(t)) {
return true;
}
}
return false;
}
public void clear() {
int size = this.mGraph.size();
for (int i = 0; i < size; i++) {
ArrayList<T> valueAt = this.mGraph.valueAt(i);
if (valueAt != null) {
poolList(valueAt);
}
}
this.mGraph.clear();
}
public ArrayList<T> getSortedList() {
this.mSortResult.clear();
this.mSortTmpMarked.clear();
int size = this.mGraph.size();
for (int i = 0; i < size; i++) {
dfs(this.mGraph.keyAt(i), this.mSortResult, this.mSortTmpMarked);
}
return this.mSortResult;
}
private void dfs(T t, ArrayList<T> arrayList, HashSet<T> hashSet) {
if (arrayList.contains(t)) {
return;
}
if (hashSet.contains(t)) {
throw new RuntimeException("This graph contains cyclic dependencies");
}
hashSet.add(t);
ArrayList<T> arrayList2 = this.mGraph.get(t);
if (arrayList2 != null) {
int size = arrayList2.size();
for (int i = 0; i < size; i++) {
dfs(arrayList2.get(i), arrayList, hashSet);
}
}
hashSet.remove(t);
arrayList.add(t);
}
int size() {
return this.mGraph.size();
}
private ArrayList<T> getEmptyList() {
ArrayList<T> acquire = this.mListPool.acquire();
return acquire == null ? new ArrayList<>() : acquire;
}
private void poolList(ArrayList<T> arrayList) {
arrayList.clear();
this.mListPool.release(arrayList);
}
}

View File

@ -0,0 +1,56 @@
package androidx.coordinatorlayout.widget;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
/* loaded from: classes.dex */
public class ViewGroupUtils {
private static final ThreadLocal<Matrix> sMatrix = new ThreadLocal<>();
private static final ThreadLocal<RectF> sRectF = new ThreadLocal<>();
static void offsetDescendantRect(ViewGroup viewGroup, View view, Rect rect) {
ThreadLocal<Matrix> threadLocal = sMatrix;
Matrix matrix = threadLocal.get();
if (matrix == null) {
matrix = new Matrix();
threadLocal.set(matrix);
} else {
matrix.reset();
}
offsetDescendantMatrix(viewGroup, view, matrix);
ThreadLocal<RectF> threadLocal2 = sRectF;
RectF rectF = threadLocal2.get();
if (rectF == null) {
rectF = new RectF();
threadLocal2.set(rectF);
}
rectF.set(rect);
matrix.mapRect(rectF);
rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f), (int) (rectF.bottom + 0.5f));
}
public static void getDescendantRect(ViewGroup viewGroup, View view, Rect rect) {
rect.set(0, 0, view.getWidth(), view.getHeight());
offsetDescendantRect(viewGroup, view, rect);
}
private static void offsetDescendantMatrix(ViewParent viewParent, View view, Matrix matrix) {
Object parent = view.getParent();
if ((parent instanceof View) && parent != viewParent) {
offsetDescendantMatrix(viewParent, (View) parent, matrix);
matrix.preTranslate(-r0.getScrollX(), -r0.getScrollY());
}
matrix.preTranslate(view.getLeft(), view.getTop());
if (view.getMatrix().isIdentity()) {
return;
}
matrix.preConcat(view.getMatrix());
}
private ViewGroupUtils() {
}
}