我正在尝试从https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#3了解 Android 房间
第四部分是关于更新 Gradle 文件。它提供了几个代码片段以包含在
build.gradle(模块:app)
我已经包含了页面上提到的所有实现、插件等。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.testing.roomwordsample"
minSdkVersion 18
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' …Run Code Online (Sandbox Code Playgroud) 我制作了一个带有秩启发式和路径压缩的不相交集模板。
template <typename T>
class disJSet
{
map<T,T> parent;
map<T,int> rank;
public:
//Linear time complexity
void makeSet(vector<T> it)
{
for(T i:it)
{
parent[i]=i;
rank[i]=0;
}
}
//Time complexity of O(log*n)
T find(T el)
{
if(el!=parent[el])
parent[el]=find(parent[el]);
return parent[el];
}
//Time complexity of O(log*n)
bool unionOp(T a,T b)
{
T a_id=find(a);
T b_id=find(b);
if(a_id==b_id)
return false;
if(rank[a_id]<rank[b_id])
parent[a_id]=b_id;
else
{
parent[b_id]=a_id;
if(rank[a_id]==rank[b_id])
{
rank[b_id]=rank[b_id]+1;
}
}
return true;
}
};
Run Code Online (Sandbox Code Playgroud)
路径压缩是在find()方法中实现的。为什么我们在路径压缩后不更新排名?
我的原因:每当有调用查找时,由于路径压缩,每个中间节点都会成为叶节点。并假设如果这是父级最长的子树,那么它的高度现在已更改。但是我们不更新父/根节点的等级。
这可能会在联合操作中产生差异。例如,两个元素的联合将导致通过比较它们的等级使一棵树成为另一棵树的子节点。但是由于调用 ,ranks 可能不代表树的最大高度find()。
auto、register、static 和extern 在C 中被称为存储类。但是为什么在C 中没有类的情况下将它们称为类呢?