我正在开发一个 Android Compose 项目,其中使用 Paging 3 和 LazyColumn 来显示从网络调用获取的项目列表。Paging 3 的默认行为是根据prefetchDistance用户滚动来加载页面,但在我的例子中,它会加载大约 15 个页面,每个页面在屏幕启动时包含 10 条记录。我尝试过将其设置prefetchDistace为 10,但不起作用。
这是我的代码: ViewModel
class ShowAllNotificationsViewModel @Inject constructor(private val pagingSource: NotificationPagingSource) :
BaseViewModel() {
private val _uiState =
MutableStateFlow<UIState<BaseResponseModel<NotificationResponseModel?>>>(UIState.StateLoading)
val uiState = _uiState.asStateFlow()
private val _isRefreshing = MutableStateFlow(false)
val isRefreshing = _isRefreshing.asStateFlow()
val items: Flow<PagingData<NotificationModel>> = Pager(
config = PagingConfig(
pageSize = 10,
prefetchDistance = 5,
enablePlaceholders = false,
),
pagingSourceFactory = { pagingSource }
)
.flow
.cachedIn(viewModelScope)
fun refreshData() {
pagingSource.invalidate() …Run Code Online (Sandbox Code Playgroud) android android-mvvm android-paging android-jetpack-compose android-paging-3
我刚刚将 GCC 编译器版本从 11.4 更新到 13.1。我发现以下代码曾经在我的旧 GCC 11.4 上运行,但不再在 GCC 13.1 上运行。
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#include <iostream>
int main() {
std::string s = "Hello World!";
std::cout << s << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
这是编译器消息:
====================[ Build | run | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2023.3.2\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\zyk\CLionProjects\run\cmake-build-debug --target run -j 18
[1/2] Building CXX object CMakeFiles/run.dir/main.cpp.obj
FAILED: CMakeFiles/run.dir/main.cpp.obj
C:\PROGRA~1\JETBRA~1\CLION2~1.2\bin\mingw\bin\G__~1.EXE -g -fdiagnostics-color=always -MD -MT CMakeFiles/run.dir/main.cpp.obj -MF CMakeFiles\run.dir\main.cpp.obj.d -o CMakeFiles/run.dir/main.cpp.obj -c C:/Users/zyk/CLionProjects/run/main.cpp
In file included from C:/Program Files/JetBrains/CLion 2023.3.2/bin/mingw/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/string:43,
from C:/Program Files/JetBrains/CLion …Run Code Online (Sandbox Code Playgroud) 当我尝试打印 preTopping 时,即使预先添加(浮动),答案也始终是 0.0000
int length, width;
printf("Please enter your pizza's length (cm): ");
scanf(" %d", &length);
printf("Please enter your pizzas width (cm): ");
scanf(" %d", &width);
float preTopping, postTopping=0;
preTopping = ((length * width) / (40 * 40)) * 60;
printf("%f", preTopping);
Run Code Online (Sandbox Code Playgroud) 我遇到了一个错误设计的带有 34 个参数的 java 对象的问题。
该对象有时可以有 3 个填充值,而其他对象必须为 null 。在第二种情况下,15 个字段被填充,其他字段必须为空等等......
我现在无法更改此对象,因为它链接到存储库模型。
有没有办法检查字段名称列表是否为空?我还考虑创建一个子对象来创建 isEmpty() 方法,以便分割支票的大小。
例如这个类“Guy”:
public class Guy {
private String name;
private String haveCar;
private String carBrand;
private String isRentedCar;
private String rentCarCompany;
public checkGuy(Guy guy){
if(guy.getHaveCar.equals("YES")){
// check if car brand exist
if ( guy.isRentedCar.equals("YES")){
// check if rent car company in db ...
}
}
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
当有人发布这个对象时,我想避免保存这个对象:
public class Guy {
private String name;
private String haveCar;
private String carBrand;
private …Run Code Online (Sandbox Code Playgroud) 我有一个免费大小的向量列表
\nset.seed(1)\ndat <- lapply(1:10, \\(x) sample(letters, size = sample(1:10,1), replace = T))\n\ndat\n\n[[1]]\n[1] "d" "g" "a" "b" "w" "k" "n" "r" "s"\n\n[[2]]\n[1] "u"\n\n[[3]]\n[1] "j" "v" "n" "j" "g"\n\n[[4]]\n[1] "o" "u" "e" "i" "y" "n" "e" "e" "b"\n\n[[5]]\n [1] "y" "l" "o" "a" "t" "c" "f" "j" "j" "f"\nRun Code Online (Sandbox Code Playgroud)\n有哪些方法可以制作像这样的密集矩阵,但效率更高?\n我也想像示例中那样保存列名称
\nlibrary(arules)\nas(transactions(dat), "matrix")\n\n\n a b c d e f g h i j k l m\n [1,] TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE\n …Run Code Online (Sandbox Code Playgroud) 我用来pandas操作数据帧并将logging中间结果以及警告和错误记录到单独的日志文件中。我还需要将一些中间数据帧打印到同一个日志文件中。具体来说,我想:
logging(以确保更轻松的调试并避免写入许多中间文件,就像调用to_csv文件目标的情况一样),logging使用level控制日志记录的详细程度(通常是这样做的),例如DEBUG或INFO,与其他日志记录消息(包括那些与数据帧无关的消息)的详细程度共享。240102 10:58:20 INFO:.我能想到的最好的是下面的代码,这有点太冗长了。有没有一种更简单、更Pythonic的方法来记录数据帧切片?
\n笔记:
\n请附上使用示例。
\n例子:
\nimport io\nimport logging\nimport pandas as pd\n\n# Print into log this many lines of several intermediate dataframes,\n# set to 20 or so:\nMAX_NUM_DF_LOG_LINES = 4\n\nlogging.basicConfig(\n datefmt = \'%y%m%d %H:%M:%S\',\n format = \'%(asctime)s %(levelname)s: %(message)s\')\nlogger = …Run Code Online (Sandbox Code Playgroud) 我想保留开发中的提交历史记录,但只保留 main 中的合并提交。我认为挤压合并可以做到这一点,但显然它会产生这里描述的问题:挤压合并后,提交历史记录仍然显示在合并请求中作为分支之间的差异,即使它们在那时应该是相同的。
还有其他方法可以实现此目的吗?也许我不需要在开发中保留提交,但我希望能够在我们公司的 bitbucket 帐户上浏览它们。
在 C 中,我们支持八进制、二进制、十六进制和十进制表示法。
int a = 16;
Run Code Online (Sandbox Code Playgroud)
也可以写成HEX格式
int a = 0x10 // equivalent with 16
Run Code Online (Sandbox Code Playgroud)
漂浮物呢?
float a = 5; // using IEEE 754 0x40a00000 is the equivalence
float a == 0x40a00000 // not equivalent to 5
printf("%f",a) // will output 1084227584.000000
Run Code Online (Sandbox Code Playgroud)
这是为什么?在机器级别,我可以找到存储在内存中的十六进制表示形式 40a00000。
现在大多数人不在goto他们的代码中使用语句。好的。在 SO 中,有许多线程在goto使用,所有线程都“允许”它退出深度循环。
展示一些:
我查看了cppreference.com,其中显示:
当无法使用其他语句将控制转移到所需位置时使用。
敲响我警钟的是“否则不可能”
goto任何机构都可以举出一些无法避免的例子吗?
注意:我将此问题标记为“C++”,只是因为我对 C++ 示例更感兴趣。任何其他语言对我都有好处。
我读了很多关于这个主题的回复,但我仍然无法理解。请理解我正在学习过程中。
有人告诉我,向量只不过是它的第一个元素地址,因此是一个二维向量。
那么,为什么如果我通过指针传递 2D 向量,我就会失去使用索引的能力。
int vec[10][10] = { 1, 2, 3, 4 };
int *v = vec;
Run Code Online (Sandbox Code Playgroud)
为什么我不能说
int a = v[1][1]
Run Code Online (Sandbox Code Playgroud)
就像我会做的那样
int a = vec[1][1]
Run Code Online (Sandbox Code Playgroud)
if v,那是一个指向int, 的指针,而vec, 那是一个指向int, 的指针,那么它们不是完全相同的东西,同一个对象吗?
我读到
int (*v)[N] = vec;
Run Code Online (Sandbox Code Playgroud)
其中N是列数。但这对于初学者来说似乎是一件超级棘手的事情。
为什么是这样?
编辑:
我的大脑想到了这个解释,int (*vec)[N]解释了指向向量 10 的指针的int含义。这里是。
鉴于我的理解,在二维数组中,指向第一个元素的指针是指向N元素数组的指针,这是我给自己的解释。
如果 lhs ofint *var = &int必须从右到左读取,变成“ varis a pointerto int”,那么我期望int [N] …
c ×3
c++ ×2
android ×1
android-mvvm ×1
dataframe ×1
g++ ×1
gcc ×1
git ×1
goto ×1
integer ×1
java ×1
legacy-code ×1
logging ×1
merge ×1
pandas ×1
pointers ×1
pretty-print ×1
python ×1
r ×1
validation ×1