spl

PHP lazy array mapping

感情迁移 提交于 2019-12-03 06:08:42
Is there a way of doing array_map but as an iterator? For example: foreach (new MapIterator($array, $function) as $value) { if ($value == $required) break; } The reason to do this is that $function is hard to calculate and $array has too many elements, only need to map until I find a specific value. array_map will calculate all values before I can search for the one I want. I could implement the iterator myself, but I want to know if there is a native way of doing this. I couldn't find anything searching PHP documentation. In short: No. There is no lazy iterator mapping built into PHP. There

Does really SplFixedArray perform better than arrays?

不羁的心 提交于 2019-12-03 03:33:54
I'm testing the SplFixedArray building an array with the days of the week, and I get the following results: <?php $days = new SplFixedArray(7); $days[0] = "Monday"; $days[1] = "Tuesday"; $days[2] = "Wednesday"; $days[3] = "Thursday"; $days[4] = "Friday"; $days[5] = "Saturday"; $days[6] = "Sunday"; echo memory_get_peak_usage() . "\n"; //Returns 327688 echo memory_get_usage() . "\n"; //Returns 327140 echo memory_get_peak_usage(true) . "\n"; //Returns 524288 echo memory_get_usage(true) . "\n"; //Returns 524288 With traditional arrays: <?php $days = array(); $days[0] = "Monday"; $days[1] =

How is Guava Splitter.onPattern(..).split() different from String.split(..)?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I recently harnessed the power of a look-ahead regular expression to split a String: "abc8".split("(?=\\d)|\\W") If printed to the console this expression returns: [abc, 8] Very pleased with this result, I wanted to transfer this to Guava for further development, which looked like this: Splitter.onPattern("(?=\\d)|\\W").split("abc8") To my surprise the output changed to: [abc] Why? 回答1: You found a bug! System.out.println(s.split("abc82")); // [abc, 8] System.out.println(s.split("abc8")); // [abc] This is the method that Splitter uses to

PHP SPL RecursiveDirectoryIterator RecursiveIteratorIterator retrieving the full tree

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: how can i retrieve the full directory tree using SPL ? 回答1: By default, the RecursiveIteratorIterator will use LEAVES_ONLY for the second argument to __construct . This means it will return files only. If you want to include files and directories (at least that's what I'd consider a full directory tree), you'd have to do: $iterator = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $path ), RecursiveIteratorIterator :: SELF_FIRST ); and then you can foreach over it. If you want to return the directory tree instead

Spl, ArrayObject, ArrayObject::STD_PROP_LIST

↘锁芯ラ 提交于 2019-12-03 01:28:33
I'm trying to understand STD_PROP_LIST constant in the documentation but so far i didn´t understand it, and didn´t found any explanation :( The documentation has the following example: $a = new ArrayObject(array(), ArrayObject::STD_PROP_LIST); $a['arr'] = 'array data'; $a->prop = 'prop data'; $b = new ArrayObject(); $b['arr'] = 'array data'; $b->prop = 'prop data'; // ArrayObject Object // ( // [prop] => prop data // ) print_r($a); // ArrayObject Object // ( // [arr] => array data // ) print_r($b); Both prints give me the same exact result: ArrayObject Object ( [prop] => prop data [storage

iMX6Q Sabresd Board SPL Mode

匿名 (未验证) 提交于 2019-12-03 00:32:02
uboot 2014以后的版本已经加入了支持快速启动的spl模式,本文用iMX6Q-SDP开发板做个简单讲解 在官方的yocot中下载fsl-L4.9.11_1.0.0-ga版本代码并编译,提取出uboot和kernel做为SPL模式的示范 看一下uboot官方对SPL和过去对比的描述 如下是denx对spl的描述 如下是SPL模式的简易时序图 如下针对iMX6Q Sabresd SD开发板打开SPL模式 uboot部分 开发板对应的配置文件为mx6qsabresd_defconfig 打开SPL模式需要在配置文件加入一个宏CONFIG_SPL=y 但此时还没达到快速启动的目的,需要跳过uboot直达kernel才行:boot_rom --> SPL --> kernel 为此查看uboot/README的SPL framework部分 CONFIG_SPL 此项我们在defconfig中已经打开 CONFIG_SPL_OS_BOOT 有一项说明了从SPL跳转到kernel需要打开此宏 在include/configs/mx6_common.h中加入定义#define CONFIG_SPL_OS_BOOT,然后编译 得到如下明确的错误提示 在uboot/README or 查阅未定义的宏得知具体含义 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,

u-boot-2018.05之make编译过程目标依赖分析

匿名 (未验证) 提交于 2019-12-03 00:29:01
- 第一步:配置,执行 make xxx_defconfig 进行各项配置,生成 .config 文件 ( u-boot-2018.05之make配置过程分析 ) - 第二步:编译,执行 make 进行编译,生成可执行的二进制文件u-boot.* 顶层目标依赖 _all 和 all 对 $(ALL-y) 的依赖 从顶层Makefile开始查找,首先找到的是 _all 伪目标: # That's our default target when none is given on the command line PHONY := _all _all: 紧接着会对 _all 伪目标添加 all 伪目标的依赖: PHONY += all ifeq ($(KBUILD_EXTMOD),) _all: all else _all: modules endif all 自身依赖于 $(ALL-y) all: $(ALL-y) $(ALL-y) 对 u-boot 目标文件的依赖 $(ALL-y) 定义了最终需要生成所有文件: # Always append ALL so that arch config.mk's can add custom ones ALL-y += u-boot.srec u-boot.bin u-boot.sym System.map u-boot.cfg binary

JZ2440 u-boot-2016.11、linux-4.17和busybox-1.28.4移植笔记

匿名 (未验证) 提交于 2019-12-02 21:59:42
2018年5月份开始在JZ2440上陆续移植了u-boot-2016.11、u-boot-spl-2016.11、 linux-4.17和busybox-1.28.4,其中linux-4.17和busybox-1.28.4是当时官方最新的 版本,以此作为学习linux两年来的总结。 遗憾的是,当时在移植过程中没有做每个阶段的笔记,只想尽快的完成。导致现 在都已经忘的七七八八了,几乎连编译烧录都不记得怎么操作了。移植完成后,由于 工作忙也一直没有把代码提交到github。刚好最近入手了一部新的笔记本,于是打算 把资料重新整理下。 所幸的是,git的提交日志里记录了详细的移植过程。可以通过参考提交记录了 解如何从零开始移植一个完整的Linux系统。 相对于JZ2440开发板自带的u-boot-1.1.6、linux-2.6.22.6、fs_qtopia,我自 己移植的u-boot-2016.11主要增加了独立的SPL引导u-boot,dts设备树的支持,增 加了spl和dtb的分区,我也尝试重新移植过u-boot-1.1.6,发现JZ2440开发板自带的 u-boot-1.1.6搞复杂了,修改了很多没必要的东西,看起来十分费解。如果有读者需 要的可以留言,我会提交到github。 对于linux-4.17主要是在JZ2440上增加了设备树的支持,基本外设驱动都通过设 备树来配置。

PHP - Initialize object members with array parameter

早过忘川 提交于 2019-12-02 20:59:23
问题 Is it possible to initialize an objects private or protected members in php with an associative array. for example: class TestClass { public $_name; public $_age; public function __construct(array $params) { ?????? } } $testClass = new TestClass( array( 'name' => 'Bob', 'age' => '29', ) ); i was wondering whether there is an elegant solution - perhaps by implementing one the spl interfaces or otherwise? 回答1: You mentioned SPL. But without knowing the exact requirements for the purpose of your

InvalidArgumentException vs UnexpectedValueException

◇◆丶佛笑我妖孽 提交于 2019-12-02 20:05:45
When should I use InvalidArgumentException and when UnexpectedValueException ? They look the same to me. Note that one extends LogicException and the other one extends RuntimeException, so the difference shouldn't be so subtle IMO. outis Looking closely at the descriptions on the manual pages: InvalidArgumentException Exception thrown if an argument is not of the expected type . (The description was Exception thrown if an argument does not match with the expected value. until mid-2014 , but was changed when PHP 5.6 got introduced ) UnexpectedValueException Exception thrown if a value does not