diff --git a/en/application-dev/Readme-EN.md b/en/application-dev/Readme-EN.md index 5147d8c5200157e6a2edc8091630bbf22a6b9fb6..6e40eb34a50e798f7ae75f7c8cba2804cb6dfc51 100644 --- a/en/application-dev/Readme-EN.md +++ b/en/application-dev/Readme-EN.md @@ -50,6 +50,7 @@ - [\@BuilderParam Decorator: \@Builder Function Reference](quick-start/arkts-builderparam.md) - [\@Styles Decorator: Definition of Resusable Styles](quick-start/arkts-style.md) - [\@Extend Decorator: Extension of Built-in Components](quick-start/arkts-extend.md) + - [\@AnimatableExtend Decorator: Definition of Animatable Attributes](quick-start/arkts-animatable-extend.md) - [stateStyles: Polymorphic Style](quick-start/arkts-statestyles.md) - State Management - [State Management Overview](quick-start/arkts-state-management-overview.md) @@ -77,6 +78,7 @@ - Development - [Application Models](application-models/Readme-EN.md) - [UI Development](ui/Readme-EN.md) + - [ArkTS Common Library](arkts-utils/Readme-EN.md) - [Web](web/Readme-EN.md) - [Notification](notification/Readme-EN.md) - [Window Manager](windowmanager/Readme-EN.md) diff --git a/en/application-dev/application-dev-guide-for-gitee.md b/en/application-dev/application-dev-guide-for-gitee.md index 2a5ff1426182d415f09b55868c48d4238974ba64..9770de4b35a7e23d38a0266e5e0daf826e656e00 100644 --- a/en/application-dev/application-dev-guide-for-gitee.md +++ b/en/application-dev/application-dev-guide-for-gitee.md @@ -25,7 +25,8 @@ All applications should be developed on top of these frameworks. Then, equip yourself for developing the key features, with the following guidelines: -- [Web](web/web-component-overview.md) +- [ArkTS Common Library](arkts-utils/Readme-EN.md) +- [Web](web/Readme-EN.md) - [Notification](notification/Readme-EN.md) - [Window Manager](windowmanager/Readme-EN.md) - [WebGL](webgl/Readme-EN.md) diff --git a/en/application-dev/application-dev-guide.md b/en/application-dev/application-dev-guide.md index d8bf473f9527e26eaf61c1a19757623879c4ef1d..65d3f42d95a37f3bdb9728a8e0b2897dd1ff8519 100644 --- a/en/application-dev/application-dev-guide.md +++ b/en/application-dev/application-dev-guide.md @@ -25,6 +25,7 @@ All applications should be developed on top of these frameworks. Then, equip yourself for developing the key features, with the following guidelines: +- [ArkTS Common Library](arkts-utils/arkts-commonlibrary-overview.md) - [Web](web/web-component-overview.md) - [Notification](notification/notification-overview.md) - [Window Manager](windowmanager/window-overview.md) diff --git a/en/application-dev/arkts-utils/Readme-EN.md b/en/application-dev/arkts-utils/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..a574b494aea8d5bc7b62a000044fa81ae269b43e --- /dev/null +++ b/en/application-dev/arkts-utils/Readme-EN.md @@ -0,0 +1,23 @@ +# ArkTS Common Library + +- [Overview of ArkTS Common Library](arkts-commonlibrary-overview.md) +- Concurrency + - [Concurrency Overview](concurrency-overview.md) + - Using Asynchronous Concurrency for Development + - [Asynchronous Concurrency Overview](async-concurrency-overview.md) + - [Single I/O Task Development](single-io-development.md) + - Using Multithread Concurrency for Development + - [Multithread Concurrency Overview](multi-thread-concurrency-overview.md) + - [Comparison Between TaskPool and Worker](taskpool-vs-worker.md) + - [CPU Intensive Task Development](cpu-intensive-task-development.md) + - [I/O Intensive Task Development](io-intensive-task-development.md) + - [Synchronous Task Development](sync-task-development.md) +- Container + - [Container Overview](container-overview.md) + - [Linear Containers](linear-container.md) + - [Nonlinear Containers](nonlinear-container.md) +- XML Generation, Parsing, and Conversion + - [XML Overview](xml-overview.md) + - [XML Generation](xml-generation.md) + - [XML Parsing](xml-parsing.md) + - [XML Conversion](xml-conversion.md) diff --git a/en/application-dev/arkts-utils/arkts-commonlibrary-overview.md b/en/application-dev/arkts-utils/arkts-commonlibrary-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..708f14c78da7c7bd53d66cd62826ff01c5d6e212 --- /dev/null +++ b/en/application-dev/arkts-utils/arkts-commonlibrary-overview.md @@ -0,0 +1,31 @@ +# Overview of ArkTS Common Library + + +The ArkTS common library provides common basic capabilities, as illustrated in the figure below. + + +**Figure 1** Capabilities of the ArkTS common library + +![arkts-commonlibrary](figures/arkts-commonlibrary.png) + + +- Supporting [asynchronous concurrency and multithread concurrency](concurrency-overview.md) + - Supports standard JavaScript asynchronous concurrency capabilities such as Promise and async/await. + - Uses **TaskPool** to provide a multithread running environment for applications. The use of **TaskPool** helps reduce resource consumption and improve system performance. It also frees you from caring about the lifecycle of thread instances. + - Uses **Worker** to support multithread concurrency. The worker thread can communicate with the host thread. You need to proactively create and close a worker thread. + +- Providing common capabilities of [adding, deleting, modifying, and querying elements in containers](container-overview.md) + +- Constructing and parsing XML files, URLs, and URIs + - Extensible Markup Language (XML) is designed for data transmission and storage. The common library provides APIs for [XML generation, parsing, and conversion](xml-overview.md). + - [URI](../reference/apis/js-apis-uri.md) is a uniform resource identifier that uniquely identifies a resource. [URL](../reference/apis/js-apis-url.md) is a uniform resource locator that provides a path for locating a resource. + +- Supporting common [string and binary data processing](../reference/apis/js-apis-util.md) and [logging](../reference/apis/js-apis-logs.md) + - Provides APIs to encode and decode strings. + - Provides APIs to encode and decode Base64-encoded bytes. + - Supports common rational number operations, including comparing rational numbers and obtaining numerators and denominators. + - Provides **Scope** APIs to define the valid range of a field. + - Provides APIs to process binary data in scenarios such as TCP flows or file system operations. + - Supports logging using the console. + +- Providing the capability of [obtaining process information and operating processes](../reference/apis/js-apis-process.md) \ No newline at end of file diff --git a/en/application-dev/arkts-utils/async-concurrency-overview.md b/en/application-dev/arkts-utils/async-concurrency-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..32bed2f143b9dbf32369fb439290d762269e055a --- /dev/null +++ b/en/application-dev/arkts-utils/async-concurrency-overview.md @@ -0,0 +1,87 @@ +# Asynchronous Concurrency Overview + + +Promise and async/await are standard JavaScript syntax that provides asynchronous concurrency. Asynchronous code ensures that actions initiated now finish later. It allows the execution of only one segment of code at a time and is therefore applicable to the development of a single I/O task, for example, a network request or a file read/write operation. + + +Promise and async/await allow an application to perform other operations without waiting for the completion of certain actions. + + +## Promise + +Promise is an object used to process asynchronous operations. It converts asynchronous operations into a style similar to synchronous operations for easier code writing and maintenance. Promise provides a state mechanism to manage different phases of asynchronous operations. It also provides methods to register callback functions to handle the success or failure of these operations. + +Promise has three states: pending, fulfilled, and rejected. After being created, a Promise object is in the pending state and changes to the fulfilled or rejected state when the asynchronous operation is complete. + +The most common usage for Promise is to instantiate a Promise object through a constructor and pass in a function (usually named **executor**) with two parameters. The **executor** function receives two parameters: **resolve** and **reject**, which represent the callback functions that should be called when the asynchronous operation succeeds and fails, respectively. The code snippet below creates a Promise object and simulates an asynchronous operation: + + +```js +const promise = new Promise((resolve, reject) => { + setTimeout(() => { + const randomNumber = Math.random(); + if (randomNumber > 0.5) { + resolve(randomNumber); + } else { + reject(new Error('Random number is too small')); + } + }, 1000); +}); +``` + +In the preceding code, the **setTimeout** function simulates an asynchronous operation that randomly generates a number one second later. If the random number is greater than 0.5, the **resolve** callback function is executed and the generated random number is passed in as a parameter. Otherwise, the **reject** callback function is executed and an error object is passed in as a parameter. + +After the Promise object is created, you can use the **then** and **catch** methods to register the callback functions for the fulfilled and rejected states. The **then** method can receive two parameters: one for processing the fulfilled state and the other for processing the rejected state. If only one parameter is passed in, the callback function is executed as long as the state changes. The **catch** method receives a callback function to process the failure result, that is, capture the exception thrown when the Promise state changes to **rejected** or the operation fails. The code snippet below shows the use of **then** and **catch** methods: + + +```js +promise.then(result => { + console.info(`Random number is ${result}`); +}).catch(error => { + console.error(error.message); +}); +``` + +In the preceding code, the callback function of the **then** method receives the success result of the Promise object as a parameter and outputs it to the console. If the Promise object enters the rejected state, the callback function of the **catch** method receives the error object as a parameter and outputs it to the console. + + +## Async/Await + +Async/Await is a Promise syntax sugar used to process asynchronous operations, making it easier to read and write asynchronous code. The async keyword is used to declare an asynchronous function, and the await keyword is used to wait for Promise parsing (fulfilled or rejected). In this way, the asynchronous operation logic is coded as a synchronous operation. + +The **async** function returns a Promise object to represent an asynchronous operation. Inside the **async** function, you can use the await keyword to wait for the parsing of the Promise object and return its parsed value. If an **async** function throws an exception, the Promise object returned by the function is rejected, and the exception information is passed to the **onRejected()** method of the Promise object. + +The code snippet below uses async/await to simulate an asynchronous operation that returns a string three seconds later. + + +```js +async function myAsyncFunction() { + const result = await new Promise((resolve) => { + setTimeout(() => { + resolve('Hello, world!'); + }, 3000); + }); + console.info(String(result)); // Output: Hello, world! +} + +myAsyncFunction(); +``` + +In the preceding code, the await keyword is used to wait for the parsing of the Promise object and store its parsed value in the **result** variable. + +Note that the entire operation must be packaged in the **async** function because the code needs to wait for the asynchronous operation to complete. In addition to **await**, you can use the try/catch block to capture exceptions in asynchronous operations. + + +```js +async function myAsyncFunction() { + try { + const result = await new Promise((resolve) => { + resolve('Hello, world!'); + }); + } catch (e) { + console.error(`Get exception: ${e}`); + } +} + +myAsyncFunction(); +``` diff --git a/en/application-dev/arkts-utils/concurrency-overview.md b/en/application-dev/arkts-utils/concurrency-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..3f091f42ea1257468aba5ba9ed94e64c92f661bb --- /dev/null +++ b/en/application-dev/arkts-utils/concurrency-overview.md @@ -0,0 +1,15 @@ +# Concurrency Overview + +Concurrency refers to the capability of processing multiple tasks in the same period. To improve the response speed and frame rate of applications and prevent time-consuming tasks from blocking the main thread, OpenHarmony provides two policies: asynchronous concurrency and multithread concurrency. + +- Asynchronous concurrency means that an action in asynchronous code is suspended and will continue later. Only one segment of code is being executed at a time. + +- Multithread concurrency allows multiple segments of code to be executed at a time. When the main thread continues to respond to user operations and update the UI, time-consuming operations are performed in the background to avoid application freezing. + +Concurrency is used in a variety of scenarios, including a single I/O task, CPU intensive task, I/O intensive task, synchronous task, and the like. You can select a concurrency policy based on your scenario. + +ArkTS provides the following mechanisms to support asynchronous concurrency and multithread concurrency: + +- Promise and async/await: provide asynchronous concurrency and apply to the development of a single I/O task. For details, see [Asynchronous Concurrency Overview](async-concurrency-overview.md). + +- **TaskPool** and **Worker**: provide multithread concurrency and apply to the development of CPU intensive tasks, I/O intensive tasks, and synchronous tasks. For details, see [Multithread Concurrency Overview](multi-thread-concurrency-overview.md). diff --git a/en/application-dev/arkts-utils/container-overview.md b/en/application-dev/arkts-utils/container-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..8a317e23167644ad72287c05672c3aa4a641cd29 --- /dev/null +++ b/en/application-dev/arkts-utils/container-overview.md @@ -0,0 +1,7 @@ +# Overview of Containers + +The container classes provide a set of methods to process elements of various data types stored in containers. + +The container classes are implemented in a way similar to static languages. By restricting storage locations and attributes, they remove redundant logic for each type of data while providing the complete functionalities, ensuring efficient data access and improving application performance. + +Currently, OpenHarmony provides 14 types of linear and non-linear containers, each of which has its own features and uses cases. For details, see [Linear Containers](linear-container.md) and [Nonlinear Containers](nonlinear-container.md). diff --git a/en/application-dev/arkts-utils/cpu-intensive-task-development.md b/en/application-dev/arkts-utils/cpu-intensive-task-development.md new file mode 100644 index 0000000000000000000000000000000000000000..80ecd66bb86f11bb4b0dace92e8e6924bdbd8b4f --- /dev/null +++ b/en/application-dev/arkts-utils/cpu-intensive-task-development.md @@ -0,0 +1,191 @@ +# CPU Intensive Task Development + + +CPU intensive tasks occupy lots of system computing resources for a long period of time, during which other events of the thread are blocked. Example CPU intensive tasks are image processing, video encoding, and data analysis. + + +OpenHarmony uses multithread concurrency to process CPU intensive tasks. This improves CPU utilization and application response speed. + + +If a task does not need to occupy a background thread for a long time (3 minutes), you are advised to use **TaskPool**. Otherwise, use **Worker**. The following uses histogram processing and a time-consuming model prediction task in the background as examples. + + +## Using TaskPool to Process Histograms + +1. Implement the logic of image processing. + +2. Segment the data, and initiate associated task scheduling through task groups. + Create a [task group](../reference/apis/js-apis-taskpool.md#taskgroup10), call [addTask()](../reference/apis/js-apis-taskpool.md#addtask10) to add tasks, call [execute()](../reference/apis/js-apis-taskpool.md#taskpoolexecute10) to execute the tasks in the task group, and set [a high priority](../reference/apis/js-apis-taskpool.md#priority) for the task group. After all the tasks in the task group are complete, the histogram processing result is returned simultaneously. + +3. Summarize and process the result arrays. + + +```ts +import taskpool from '@ohos.taskpool'; + +@Concurrent +function imageProcessing(dataSlice: ArrayBuffer) { + // Step 1: Perform specific image processing operations and other time-consuming operations. + return dataSlice; +} + +function histogramStatistic(pixelBuffer: ArrayBuffer) { + // Step 2: Perform concurrent scheduling for data in three segments. + let number = pixelBuffer.byteLength / 3; + let buffer1 = pixelBuffer.slice(0, number); + let buffer2 = pixelBuffer.slice(number, number * 2); + let buffer3 = pixelBuffer.slice(number * 2); + + let group = new taskpool.TaskGroup(); + group.addTask(imageProcessing, buffer1); + group.addTask(imageProcessing, buffer2); + group.addTask(imageProcessing, buffer3); + + taskpool.execute(group, taskpool.Priority.HIGH).then((ret: ArrayBuffer[]) => { + // Step 3: Summarize and process the result arrays. + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let data: ArrayBuffer; + histogramStatistic(data); + }) + } + .width('100%') + } + .height('100%') + } +} +``` + + +## Using Worker for Time-Consuming Data Analysis + +The following uses the training of a region-specific house price prediction model as an example. This model can be used to predict house prices in the region based on the house area and number of rooms. The model needs to run for a long time, and the prediction will use the previous running result. Due to these considerations, **Worker** is used for the development. + +1. Add the worker creation template provided on DevEco Studio to your project, and name it **MyWorker**. + + ![newWorker](figures/newWorker.png) + +2. In the main thread, call [ThreadWorker()](../reference/apis/js-apis-worker.md#threadworker9) to create a **Worker** object. The calling thread is the host thread. + + ```js + import worker from '@ohos.worker'; + + const workerInstance = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts'); + ``` + +3. In the host thread, call [onmessage()](../reference/apis/js-apis-worker.md#onmessage9) to receive messages from the worker thread, and call [postMessage()](../reference/apis/js-apis-worker.md#postmessage9) to send messages to the worker thread. + + For example, the host thread sends training and prediction messages to the worker thread, and receives messages sent back by the worker thread. + + + ```js + // Receive the result of the worker thread. + workerInstance.onmessage = function(e) { + // data carries the information sent by the main thread. + let data = e.data; + console.info('MyWorker.ts onmessage'); + // Perform time-consuming operations in the worker thread. + } + + workerInstance.onerror = function (d) { + // Receive error information of the worker thread. + } + + // Send a training message to the worker thread. + workerInstance.postMessage({ 'type': 0 }); + // Send a prediction message to the worker thread. + workerInstance.postMessage({ 'type': 1, 'value': [90, 5] }); + ``` + +4. Bind the **Worker** object in the **MyWorker.ts** file. The calling thread is the worker thread. + + ```js + import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker'; + + let workerPort: ThreadWorkerGlobalScope = worker.workerPort; + ``` + +5. In the worker thread, call [onmessage()](../reference/apis/js-apis-worker.md#onmessage9-1) to receive messages sent by the host thread, and call [postMessage()](../reference/apis/js-apis-worker.md#postmessage9-2) to send messages to the host thread. + + For example, the prediction model and its training process are defined in the worker thread, and messages are exchanged with the main thread. + + + ```js + import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker'; + + let workerPort: ThreadWorkerGlobalScope = worker.workerPort; + + // Define the training model and result. + let result; + + // Define the prediction function. + function predict(x) { + return result[x]; + } + + // Define the optimizer training process. + function optimize() { + result = {}; + } + + // onmessage logic of the worker thread. + workerPort.onmessage = function (e: MessageEvents) { + let data = e.data + // Perform operations based on the type of data to transmit. + switch (data.type) { + case 0: + // Perform training. + optimize(); + // Send a training success message to the main thread after training is complete. + workerPort.postMessage({ type: 'message', value: 'train success.' }); + break; + case 1: + // Execute the prediction. + const output = predict(data.value); + // Send the prediction result to the main thread. + workerPort.postMessage({ type: 'predict', value: output }); + break; + default: + workerPort.postMessage({ type: 'message', value: 'send message is invalid' }); + break; + } + } + ``` + +6. After the task is completed in the worker thread, destroy the worker thread. The worker thread can be destroyed by itself or the host thread. Then, call [onexit()](../reference/apis/js-apis-worker.md#onexit9) in the host thread to define the processing logic after the worker thread is destroyed. + + + ```js + // After the worker thread is destroyed, execute the onexit() callback. + workerInstance.onexit = function() { + console.info("main thread terminate"); + } + ``` + + In the host thread, call [terminate()](../reference/apis/js-apis-worker.md#terminate9) to destroy the worker thread and stop the worker thread from receiving messages. + + + ```js + // Destroy the worker thread. + workerInstance.terminate(); + ``` + + In the worker thread, call [close()](../reference/apis/js-apis-worker.md#close9) to destroy the worker thread and stop the worker thread from receiving messages. + + ```js + // Destroy the worker thread. + workerPort.close(); + ``` diff --git a/en/application-dev/arkts-utils/figures/arkts-commonlibrary.png b/en/application-dev/arkts-utils/figures/arkts-commonlibrary.png new file mode 100644 index 0000000000000000000000000000000000000000..e8590f0115429b7857e3d7d44b7dceb821857515 Binary files /dev/null and b/en/application-dev/arkts-utils/figures/arkts-commonlibrary.png differ diff --git a/en/application-dev/arkts-utils/figures/newWorker.png b/en/application-dev/arkts-utils/figures/newWorker.png new file mode 100644 index 0000000000000000000000000000000000000000..c1b47bb4a885cf793ed467db43151a99720ea48d Binary files /dev/null and b/en/application-dev/arkts-utils/figures/newWorker.png differ diff --git a/en/application-dev/arkts-utils/figures/taskpool.png b/en/application-dev/arkts-utils/figures/taskpool.png new file mode 100644 index 0000000000000000000000000000000000000000..f5ae190d4dece65d196fd635b08ae6b420b6033b Binary files /dev/null and b/en/application-dev/arkts-utils/figures/taskpool.png differ diff --git a/en/application-dev/arkts-utils/figures/worker.png b/en/application-dev/arkts-utils/figures/worker.png new file mode 100644 index 0000000000000000000000000000000000000000..5feb2f6e5a01e4686a3cb3fe2451d72ae80c8685 Binary files /dev/null and b/en/application-dev/arkts-utils/figures/worker.png differ diff --git a/en/application-dev/arkts-utils/io-intensive-task-development.md b/en/application-dev/arkts-utils/io-intensive-task-development.md new file mode 100644 index 0000000000000000000000000000000000000000..562f749fd99daff42359af2598bc42483dc5595c --- /dev/null +++ b/en/application-dev/arkts-utils/io-intensive-task-development.md @@ -0,0 +1,51 @@ +# I/O Intensive Task Development + + +Asynchronous concurrency can solve the problem of a single blocking I/O operation. In the case of I/O intensive tasks, the execution of other tasks in the thread is still blocked. To resolve this issue, multithread concurrency is introduced. + + +The performance focus of I/O intensive tasks is not the CPU processing capability, but the speed and efficiency of I/O operations, since such a task usually requires frequent operations such as disk read/write and network communication. The following uses frequent read/write operations on a system file to simulate concurrency processing of I/O intensive tasks. + + +1. Define a concurrency function that internally calls I/O capabilities intensively. + + ```ts + import fs from '@ohos.file.fs'; + + // Define a concurrency function that internally calls I/O capabilities intensively. + @Concurrent + async function concurrentTest(fileList: string[]) { + // Implement file writing. + async function write(data, filePath) { + let file = await fs.open(filePath, fs.OpenMode.READ_WRITE); + await fs.write(file.fd, data); + fs.close(file); + } + // Write the file cyclically. + for (let i = 0; i < fileList.length; i++) { + write('Hello World!', fileList[i]).then(() => { + console.info(`Succeeded in writing the file. FileList: ${fileList[i]}`); + }).catch((err) => { + console.error(`Failed to write the file. Code is ${err.code}, message is ${err.message}`) + return false; + }) + } + return true; + } + ``` + +2. Use **TaskPool** to execute the concurrency function that contains the intensive I/O operations. Specifically, call [execute()](../reference/apis/js-apis-taskpool.md#taskpoolexecute) to execute the tasks and process the scheduling result in a callback. For details about how to obtain **filePath1** and **filePath2** in the example, see [Obtaining Application File Paths](../application-models/application-context-stage.md#obtaining-application-file-paths). + + ```ts + import taskpool from '@ohos.taskpool'; + + let filePath1 =...; // Application file path + let filePath2 = ...; + + // Use TaskPool to execute the concurrency function that contains the intensive I/O operations. + // In the case of a large array, the distribution of I/O intensive tasks also preempts the main thread. Therefore, multiple threads are required. + taskpool.execute(concurrentTest, [filePath1, filePath2]).then((ret) => { + // Process the scheduling result. + console.info(`The result: ${ret}`); + }) + ``` diff --git a/en/application-dev/arkts-utils/linear-container.md b/en/application-dev/arkts-utils/linear-container.md new file mode 100644 index 0000000000000000000000000000000000000000..2a160f113f68e3257278e5a18168bb811a8efe30 --- /dev/null +++ b/en/application-dev/arkts-utils/linear-container.md @@ -0,0 +1,253 @@ +# Linear Containers + + +Linear containers implement a data structure that enables sequential access. The bottom layer of linear containers is implemented through arrays. OpenHarmony provides the following linear containers: **ArrayList**, **Vector**, **List**, **LinkedList**, **Deque**, **Queue**, and **Stack**. + + +Fully considering the data access speed, linear containers support Create, Read, Update, and Delete (CRUD) through a bytecode instruction at runtime. + + +## ArrayList + +[ArrayList](../reference/apis/js-apis-arraylist.md) is a dynamic array that can be used to construct a global array object. You are advised to use **ArrayList** when elements in a container need to be frequently read. + +**ArrayList** uses generics and must be stored in a contiguous memory space. Its initial capacity is 10, and it increases capacity 1.5-fold in each dynamic expansion. + +**ArrayList** provides the following CRUD APIs. + +| Operation| Description| +| --------- | ------- | +| Adding elements| Use **add(element: T)** to add an element at the end of this container.| +| Adding elements| Use **insert(element: T, index: number)** to insert an element at a given position (specified by **index**).| +| Accessing elements| Use **arr\[index]** to obtain the value at a given position (specified by **index**).| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, arrlist?: ArrayList<T>) => void, thisArg?: Object): void** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **arr\[index] = xxx** to change the value at a given position (specified by **index**).| +| Deleting elements| Use **remove(element: T)** to remove the first occurrence of the specified element.| +| Deleting elements| Use **removeByRange(fromIndex: number, toIndex: number)** to remove all of the elements within a range.| + + +## Vector + +[Vector](../reference/apis/js-apis-vector.md) is a continuous storage structure that can be used to construct a global array object. **Vector** uses generics and must be stored in a contiguous memory space. Its initial capacity is 10, and it has capacity doubled in each dynamic expansion. + +Both **Vector** and [ArrayList](../reference/apis/js-apis-arraylist.md) are implemented based on arrays, but **Vector** provides more interfaces for operating the arrays. In addition to operator access, **Vector** provides the getter and setter to provide a more complete verification and error tolerance mechanism. + +The APIs provided by **Vector** are deprecated since API version 9. You are advised to use [ArrayList](../reference/apis/js-apis-arraylist.md). + +**Vector** provides the following CRUD APIs. + +| Operation| Description| +| --------- | ------- | +| Adding elements| Use **add(element: T)** to add an element at the end of this container.| +| Adding elements| Use **insert(element: T, index: number)** to insert an element at a given position (specified by **index**).| +| Accessing elements| Use **vec\[index]** to obtain the value at a given position (specified by **index**).| +| Accessing elements| Use **get(index: number)** to obtain the element at a given position (specified by **index**).| +| Accessing elements| Use **getLastElement()** to obtain the last element in this container.| +| Accessing elements| Use **getlndexOf(element: T)** to obtain the index of the first occurrence of the specified element.| +| Accessing elements| Use **getLastlndexOf(element: T)** to obtain the index of the last occurrence of the specified element.| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, Vector?: Vector<T>) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **vec\[index]=xxx** to change the value at a given position (specified by **index**).| +| Modifying elements| Use **set(index: number, element: T)** to replace an element at a given position (specified by **index**) with a given element.| +| Modifying elements| Use **setLength(newSize: number)** to set the size of this container.| +| Deleting elements| Use **removeBylndex(index: number)** to remove the value at a given position (specified by **index**).| +| Deleting elements| Use **remove(element: T)** to remove the first occurrence of the specified element.| +| Deleting elements| Use **removeByRange(fromIndex: number, toIndex: number)** to remove all of the elements within a range.| + + +## List + +[List](../reference/apis/js-apis-list.md) can be used to construct a singly linked list, which supports access only through the head node to the tail node. **List** uses generics and can be stored in a non-contiguous memory space. + +Unlike [LinkedList](../reference/apis/js-apis-linkedlist.md), which is a doubly linked list, **List** is a singly linked list that does not support insertion or removal at both ends. + +You are advised to use **List** for frequent insertion and removal operations. + +**List** provides the following CRUD APIs. + +| Operation| Description| +| --------- | ------ | +| Adding elements| Use **add(element: T)** to add an element at the end of this container.| +| Adding elements| Use **insert(element: T, index: number)** to insert an element at a given position (specified by **index**).| +| Accessing elements| Use **list\[index]** to obtain the value at a given position (specified by **index**).| +| Accessing elements| Use **get(index: number)** to obtain the element at a given position (specified by **index**).| +| Accessing elements| Use **getFirst()** to obtain the first element in this container.| +| Accessing elements| Use **getLast()** to obtain the last element in this container.| +| Accessing elements| Use **getlndexOf(element: T)** to obtain the index of the first occurrence of the specified element.| +| Accessing elements| Use **getLastlndexOf(element: T)** to obtain the index of the last occurrence of the specified element.| +| Accessing elements| Use **forEach(callbackfn: (value: T, index?: number, list?: List<T>)=> void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **list\[index] = xxx** to change the value at a given position (specified by **index**).| +| Modifying elements| Use **set(index: number, element: T)** to replace an element at a given position (specified by **index**) with a given element.| +| Modifying elements| Use **replaceAllElements(callbackFn:(value: T,index?: number,list?: List<T>)=>T,thisArg?: Object)** to replace all elements in this container with new elements.| +| Deleting elements| Use **removeBylndex(index: number)** to remove the value at a given position (specified by **index**).| +| Deleting elements| Use **remove(element: T)** to remove the first occurrence of the specified element.| + + +## LinkedList + +[LinkedList](../reference/apis/js-apis-linkedlist.md) can be used to construct a doubly linked list, which can be traversed at both ends. **LinkedList** uses generics and can be stored in a non-contiguous memory space. + +Unlike [List](../reference/apis/js-apis-list.md), which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends. + +**LinkedList** is more efficient in data insertion than [ArrayList](../reference/apis/js-apis-arraylist.md), but less efficient in data access. + +You are advised to use **LinkedList** for frequent insertion and removal operations. + +**LinkedList** provides the following CRUD APIs. + +| Operation| Description| +| ---------- | ------ | +| Adding elements| Use **add(element: T)** to add an element at the end of this container.| +| Adding elements| Use **insert(index: number, element: T)** to insert an element at a given position (specified by **index**).| +| Accessing elements| Use **list\[index]** to obtain the value at a given position (specified by **index**).| +| Accessing elements| Use **get(index: number)** to obtain the element at a given position (specified by **index**).| +| Accessing elements| Use **getFirst()** to obtain the first element in this container.| +| Accessing elements| Use **getLast()** to obtain the last element in this container.| +| Accessing elements| Use **getlndexOf(element: T)** to obtain the index of the first occurrence of the specified element.| +| Accessing elements| Use **getLastlndexOf(element: T)** to obtain the index of the last occurrence of the specified element.| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, list?: LinkedList<T>) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **list\[index]=xxx** to change the value at a given position (specified by **index**).| +| Modifying elements| Use **set(index: number, element: T)** to replace an element at a given position (specified by **index**) with a given element.| +| Deleting elements| Use **removeBylndex(index: number)** to remove the value at a given position (specified by **index**).| +| Deleting elements| Use **remove(element: T)** to remove the first occurrence of the specified element.| + + +## Deque + +[Deque](../reference/apis/js-apis-deque.md) can be used to construct a double-ended queue (deque) that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. + +**Deque** uses generics and must be stored in a contiguous memory space. Its initial capacity is 8, and it has capacity doubled in each dynamic expansion. The bottom layer of **Deque** is implemented by cyclic queues, delivering a high efficiency in enqueuing and dequeuing. + +[Queue](../reference/apis/js-apis-queue.md) follows the principle of FIFO only and allows element removal at the front and insertion at the rear. + +[Vector](../reference/apis/js-apis-vector.md) supports insertion and deletion of elements in between, as well as at both the ends. When compared with **Vector**, **Deque** is more efficient in inserting and removing header elements, but less efficient in accessing elements. + +You are advised to use **Deque** when you need to frequently insert or remove elements at both the ends of a container. + +**Deque** provides the following CRUD APIs. + +| Operation| Description| +| ---------- | ------ | +| Adding elements| Use **insertFront(element: T)** to insert an element at the front of this container.| +| Adding elements| Use **insertEnd(element: T)** to insert an element at the end of this container.| +| Accessing elements| Use **getFirst()** to obtain the value of the first element in this container, without removing it from the container.| +| Accessing elements| Use **getLast()** to obtain the value of the last element in this container, without removing it from the container.| +| Accessing elements| Use **popFirst()** to obtain the value of the first element in this container and remove it from the container.| +| Accessing elements| Use **popLast()** to obtain the value of the last element in this container and remove it from the container.| +| Accessing elements| Use **forEach(callbackFn:(value: T, index?: number, deque?: Deque<T>) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **forEach(callbackFn:(value: T, index?: number, deque?: Deque<T>)=> void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **popFirst()** to remove the first element from this container.| +| Deleting elements| Use **popLast()** to remove the last element from this container.| + + +## Queue + +[Queue](../reference/apis/js-apis-queue.md) can be used to construct a queue that follows the FIFO principle. + +**Queue** uses generics and must be stored in a contiguous memory space. Its initial capacity is 8, and it has capacity doubled in each dynamic expansion. + +The bottom layer of **Queue** is implemented by cyclic queues, delivering a high efficiency in enqueuing and dequeuing. + +Unlike [Deque](../reference/apis/js-apis-deque.md), which supports insertion and removal at both the ends, **Queue** supports insertion at one end and removal at the other end. + +You are advised to use **Queue** in FIFO scenarios. + +**Queue** provides the following CRUD APIs. + +| Operation| Description| +| ---------- | ------ | +| Adding elements| Use **add(element: T)** to add an element at the end of this container.| +| Accessing elements| Use **getFirst()** to obtain the value of the first element in this container, without removing it from the container.| +| Accessing elements| Use **pop()** to obtain the value of the first element in this container and remove it from the container.| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, queue?: Queue<T>) => void,thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **forEach(callbackFn:(value: T, index?: number, queue?: Queue<T>) => void,thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **pop()** to remove the first element from this container.| + + +## Stack + +[Stack](../reference/apis/js-apis-stack.md) can be used to construct a stack that follows the Last Out First In (LOFI) principle. + +**Stack** uses generics and must be stored in a contiguous memory space. Its initial capacity is 8, and it increases capacity 1.5-fold in each dynamic expansion. The bottom layer of **Stack** is implemented based on arrays. It supports data insertion and removal at one end. + +Unlike [Queue](../reference/apis/js-apis-queue.md), which is implemented based on the queue data structure and supports insertion at one end and removal at the other end, **Stack** supports insertion and removal at the same end. + +You are advised to use **Stack** in LOFI scenarios. + +**Stack** provides the following CRUD APIs. + +| Operation| Description| +| ---------- | ------ | +| Adding elements| Use **push(item: T)** to add an element at the top of this container.| +| Accessing elements| Use **peek()** to obtain the value of the top element in this container, without removing it from the container.| +| Accessing elements| Use **pop()** to obtain the value of the top element in this container and remove it from the container.| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, stack?: Stack<T>) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Accessing elements| Use **locate(element: T)** to obtain the index of the first occurrence of the specified element.| +| Modifying elements| Use **forEach(callbackFn:(value: T, index?: number, stack?: Stack<T>) => void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **pop()** to remove the top element from this container.| + + +## Use of Linear Containers + +Refer to the code snippet below to add, access, and modify elements in **ArrayList**, **Vector**, **Deque**, **Stack**, and **List**. + + +```js +// ArrayList +import ArrayList from '@ohos.util.ArrayList'; // Import the ArrayList module. + +let arrayList = new ArrayList(); +arrayList.add('a'); +arrayList.add(1); // Add an element. +console.info(`result: ${arrayList[0]}`); // Access an element. +arrayList[0] = 'one'; // Modify an element. +console.info(`result: ${arrayList[0]}`); + +// Vector +import Vector from '@ohos.util.Vector'; // Import the Vector module. + +let vector = new Vector(); +vector.add('a'); +let b1 = [1, 2, 3]; +vector.add(b1); +vector.add(false); // Add an element. +console.info(`result: ${vector[0]}`); // Access an element. +console.info(`result: ${vector.getFirstElement()}`); // Access an element. + +// Deque +import Deque from '@ohos.util.Deque'; // Import the Deque module. + +let deque = new Deque; +deque.insertFront('a'); +deque.insertFront(1); // Add an element. +console.info(`result: ${deque[0]}`); // Access an element. +deque[0] = 'one'; // Modify an element. +console.info(`result: ${deque[0]}`); + +// Stack +import Stack from '@ohos.util.Stack'; // Import the Stack module. + +let stack = new Stack(); +stack.push('a'); +stack.push(1); // Add an element. +console.info(`result: ${stack[0]}`); // Access an element. +stack.pop(); // Remove an element. +console.info(`result: ${stack.length}`); + +// List +import List from '@ohos.util.List'; // Import the List module. + +let list = new List; +list.add('a'); +list.add(1); +let b2 = [1, 2, 3]; +list.add(b2); // Add an element. +console.info(`result: ${list[0]}`); // Access an element. +console.info(`result: ${list.get(0)}`); // Access an element. +``` diff --git a/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md b/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..2d42ea1a56cd56eb06cd1e8394735e17fed70a2b --- /dev/null +++ b/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md @@ -0,0 +1,53 @@ +# Multithread Concurrency Overview + + +## Overview + +Concurrency models are used to implement concurrent tasks in different scenarios. Common concurrency models are classified into shared memory models and message passing models. + +A typical message passing model is actor. It provides a relatively high degree of concurrency while eliminating a series of complex and occasional issues caused by locks. For these reasons, ArkTS chooses the actor model. + +Due to the memory isolation feature of the actor model, cross-thread serialization is required. + + +## Data Transfer Objects + +Data objects that can be transferred are classified into three types: [common objects](#common-objects), [transferable objects](#transferable-objects), and [shared objects](#shared-objects). + + +### Common Objects + +The structured clone algorithm is used for serialization of common objects. This algorithm recursively transfers an object by clone. It supports more object types than other serialization algorithms. + +The following object types are supported: basic types except Symbol, Date, String, RegExp, Array, Map, Set, Object (simple objects only, for example, objects created using **{}** or **new Object**), ArrayBuffer, and typedArray. (Note that only attributes can be transferred for common objects. Prototypes and methods cannot be transferred.) + + +### Transferable Objects + +Transferable objects are serialized through address transfer. It transfers the ownership of an object of the ArrayBuffer type object, rather than the content in it. After the ownership is transferred, the object becomes unavailable in the sender and can be used only in the receiver. + + +```js +// Define a transferable object. +let buffer = new ArrayBuffer(100); +``` + + +### Shared Objects + +A shared object is of the **SharedArrayBuffer** type, has a fixed length, and can store any type of data including numbers and strings. + +An object of the SharedArrayBuffer type can be transferred between multiple threads. The objects before and after the transfer point to the same memory block, achieving memory sharing. + +If multiple operations are simultaneously performed to modify data stored in an object of the SharedArrayBuffer type, you must use atomics to ensure data synchronization. Atomics ensure that the current operation is complete before the next operation starts. + + +```js +// Define a shared object, which uses atomics to ensure data synchronization. +let sharedBuffer = new SharedArrayBuffer(1024); +``` + + +## TaskPool and Worker + +ArkTS provides two multithread concurrency capabilities: **TaskPool** and **Worker**, which differ in their implementation features and use cases. For details, see [Comparison Between TaskPool and Worker](taskpool-vs-worker.md). diff --git a/en/application-dev/arkts-utils/nonlinear-container.md b/en/application-dev/arkts-utils/nonlinear-container.md new file mode 100644 index 0000000000000000000000000000000000000000..3287d2675528cd73c0e43c562263b5af07bfaf46 --- /dev/null +++ b/en/application-dev/arkts-utils/nonlinear-container.md @@ -0,0 +1,253 @@ +# Nonlinear Containers + + +Nonlinear containers implement a data structure that enables quick search. The bottom layer of nonlinear containers is implemented through hash tables or red-black trees. OpenHarmony provides the following nonlinear containers: **HashMap**, **HashSet**, **TreeMap**, **TreeSet**, **LightWeightMap**, **LightWeightSet**, and **PlainArray**. The types of **key** and **value** in nonlinear containers must meet the ECMA standard. + + +## HashMap + +[HashMap](../reference/apis/js-apis-hashmap.md) is used to store a set of associated key-value (KV) pairs. In a hash map, each key is unique and corresponds to a value. + +**HashMap** uses generics. In a hash map, a key is located based on its hash code. The initial capacity of a hash map is 16, and it has capacity doubled in each dynamic expansion. The bottom layer of **HashMap** is implemented based on a hash table. It uses chaining to avoid collisions in hash tables. + +**HashMap** is faster in accessing data than [TreeMap](../reference/apis/js-apis-treemap.md), because the former accesses the keys based on the hash codes, whereas the latter stores and accesses the keys in sorted order. + +[HashSet](../reference/apis/js-apis-hashset.md) is implemented based on **HashMap**. The input parameter of **HashMap** consists of **key** and **value**. In **HashSet**, only the **value** object is processed. + +You are advised to use **HashMap** when you need to quickly access, remove, and insert KV pairs. + +**HashMap** provides the following Create, Read, Update, and Delete (CRUD) APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **set(key: K, value: V)** to add an element (a KV pair) to this container.| +| Accessing elements| Use **get(key: K)** to obtain the value of the specified key.| +| Accessing elements| Use **keys()** to return an iterator that contains all the keys in this container.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: HashMap) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<[K,V]>** for data access.| +| Modifying elements| Use **replace(key: K, newValue: V)** to change the value of the specified key.| +| Modifying elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: HashMap) => void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **remove(key: K)** to remove an element with the specified key.| +| Deleting elements| Use **clear()** to clear this container.| + + +## HashSet + +[HashSet](../reference/apis/js-apis-hashset.md) is used to store a set of values, each of which is unique in a hash set. + +**HashSet** uses generics. In a hash set, a value is located based on its hash code. The initial capacity of a hash set is 16, and it has capacity doubled in each dynamic expansion. The type of **value** must comply with the ECMA standard. The bottom layer of **HashSet** is implemented based on a hash table. It uses chaining to avoid collisions in hash tables. + +**HashSet** is implemented based on [HashMap](../reference/apis/js-apis-hashmap.md). In **HashSet**, only the **value** object is processed. + +Unlike [TreeSet](../reference/apis/js-apis-treeset.md), which stores and accesses data in sorted order, **HashSet** stores data in a random order. This means that **HashSet** may use a different order when storing and accessing elements. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**. + +You are advised to use **HashSet** when you need a set that has only unique elements or need to deduplicate a set. + +**HashSet** provides the following CRUD APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **add(value: T)** to add a value to this container.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: HashSet) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: HashSet) => void, thisArg?: Object)** to change a value in this container.| +| Deleting elements| Use **remove(value: T)** to remove a value.| +| Deleting elements| Use **clear()** to clear this container.| + + +## TreeMap + +[TreeMap](../reference/apis/js-apis-treemap.md) is used to store a set of associated KV pairs. In a tree map, each key is unique and corresponds to a value. + +**TreeMap** uses generics, and the keys in a tree map are ordered. The bottom layer of **TreeMap** is a binary tree, which supports quick search of KV pairs through the children (left child and right child) of the tree. The type of **key** must comply with the ECMA standard. Keys in a tree map are stored in order. The bottom layer of **TreeMap** is implemented based on the red-black tree and supports quick insertion and removal. + +[HashMap](../reference/apis/js-apis-hashmap.md) is faster in accessing data than **TreeMap**, because the former accesses the keys based on the hash codes, whereas the latter stores and accesses the keys in sorted order. + +You are advised to use **TreeMap** when you need to store KV pairs in sorted order. + +**TreeMap** provides the following CRUD APIs. + +| Operation| Description| +| ------- | ------ | +| Adding elements| Use **set(key: K, value: V)** to add an element (a KV pair) to this container.| +| Accessing elements| Use **get(key: K)** to obtain the value of the specified key.| +| Accessing elements| Use **getFirstKey()** to obtain the first key in this container.| +| Accessing elements| Use **getLastKey()** to obtain the last key in this container.| +| Accessing elements| Use **keys()** to return an iterator that contains all the keys in this container.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: TreeMap) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator\<[K,V]>** for data access.| +| Modifying elements| Use **replace(key: K, newValue: V)** to change the value of the specified key.| +| Modifying elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: TreeMap) => void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **remove(key: K)** to remove an element with the specified key.| +| Deleting elements| Use **clear()** to clear this container.| + + +## TreeSet + +[TreeSet](../reference/apis/js-apis-treeset.md) is used to store a set of values, each of which is unique in a tree set. + +**TreeSet** uses generics, and the values in a tree set are ordered. The bottom layer of **TreeSet** is a binary tree, which supports quick search of a value through the children (left child and right child) of the tree. The type of **value** must meet the ECMA standard. Values in a tree set are stored in order. The bottom layer of **TreeSet** is implemented based on the red-black tree and supports quick insertion and removal. + +**TreeSet** is implemented based on [TreeMap](../reference/apis/js-apis-treemap.md). In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique. + +[HashSet](../reference/apis/js-apis-hashset.md) stores data in a random order, whereas **TreeSet** stores data in sorted order. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**. + +You are advised to use **TreeSet** when you need to store data in sorted order. + +**TreeSet** provides the following CRUD APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **add(value: T)** to add a value to this container.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **getFirstValue()** to obtain the first value in this container.| +| Accessing elements| Use **getLastValue()** to obtain the last value in this container.| +| Accessing elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: TreeSet) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: TreeSet) => void, thisArg?: Object)** to change a value in this container.| +| Deleting elements| Use **remove(value: T)** to remove a value.| +| Deleting elements| Use **clear()** to clear this container.| + + +## LightWeightMap + +[LightWeightMap](../reference/apis/js-apis-lightweightmap.md) is used to store a set of associated KV pairs. In a lightweight map, each key is unique and corresponds to a value. **LightWeightMap** uses generics and a more lightweight structure. It uses the hash code to uniquely identify a key at the bottom layer. It uses linear probing to avoid collisions. In a lightweight map, a key is located by using the hash code and binary search algorithm. The hash code is stored in an array and mapped to a key and its value in another array. The type of **key** must comply with the ECMA standard. + +The default initial capacity of a lightweight map is 8, and it has capacity doubled in each expansion. + +Compared with [HashMap](../reference/apis/js-apis-hashmap.md), which can also store KV pairs, **LightWeightMap** occupies less memory. + +You are advised to use **LightWeightMap** when you need to store and access **KV pairs**. + +**LightWeightMap** provides the following CRUD APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **set(key: K, value: V)** to add an element (a KV pair) to this container.| +| Accessing elements| Use **get(key: K)** to obtain the value of the specified key.| +| Accessing elements| Use **getIndexOfKey(key: K)** to obtain the index of the specified key.| +| Accessing elements| Use **getIndexOfValue(value: V)** to obtain the index of the first occurrence of the specified value.| +| Accessing elements| Use **keys()** to return an iterator that contains all the keys in this container.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **getKeyAt(index: number)** to obtain the key of an element at a given position (specified by **index**).| +| Accessing elements| Use **getValueAt(index: number)** to obtain the value of an element at a given position (specified by **index**).| +| Accessing elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: LightWeightMap) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<[K,V]>** for data access.| +| Modifying elements| Use **setValueAt(index: number, newValue: V)** to change the value of an element at a given position (specified by **index**).| +| Modifying elements| Use **forEach(callbackFn: (value?: V, key?: K, map?: LightWeightMap) => void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **remove(key: K)** to remove an element with the specified key.| +| Deleting elements| Use **removeAt(index: number)** to remove an element at a given position (specified by **index**).| +| Deleting elements| Use **clear()** to clear this container.| + + +## LightWeightSet + +[LightWeightSet](../reference/apis/js-apis-lightweightset.md) is used to store a set of values, each of which is unique in a lightweight set. + +**LightWeightSet** uses generics and a lightweight structure. Its default initial capacity is 8, and it has capacity doubled in each expansion. In a lightweight set, a value is located by using the hash code and binary search algorithm. The hash code is stored in an array and mapped to a value in another array. The type of **value** must comply with the ECMA standard. + +**LightWeightSet** uses the hash code to uniquely identify a value at the bottom layer. It uses linear probing to avoid collisions and adopts the binary search algorithm. + +Compared with [HashSet](../reference/apis/js-apis-hashset.md), which can also store values, **LightWeightSet** occupies less memory. + +You are advised to use **LightWeightSet** when you need a set that has only unique elements or need to deduplicate a set. + +**LightWeightSet** provides the following CRUD APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **add(obj: T)** to add a value to this container.| +| Accessing elements| Use **getIndexOf(key: T)** to obtain the index of a key.| +| Accessing elements| Use **values()** to return an iterator that contains all the values in this container.| +| Accessing elements| Use **entries()** to return an iterator that contains all the elements in this container.| +| Accessing elements| Use **getValueAt(index: number)** to obtain the value of an element at a given position (specified by **index**).| +| Accessing elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: LightWeightSet) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<T>** for data access.| +| Modifying elements| Use **forEach(callbackFn: (value?: T, key?: T, set?: LightWeightSet) => void, thisArg?: Object)** to change a value in this container.| +| Deleting elements| Use **remove(key: K)** to remove an element with the specified key.| +| Deleting elements| Use **removeAt(index: number)** to remove an element at a given position (specified by **index**).| +| Deleting elements| Use **clear()** to clear this container.| + + +## PlainArray + +[PlainArray](../reference/apis/js-apis-plainarray.md) is used to store a set of associated KV pairs. In a plain array, each key is unique, corresponds to a value, and is of the number type. **PlainArray** uses generics and a more lightweight structure. In a plain array, a key is located by using the binary search algorithm and is mapped to a value in another array. + +The default initial capacity of a plain array is 16, and it has capacity doubled in each expansion. + +Both **PlainArray** and [LightWeightMap](../reference/apis/js-apis-lightweightmap.md) are used to store KV pairs in the lightweight structure. However, the key type of **PlainArray** can only be **number**. + +You are advised to use PlainArray when you need to store KV pairs whose keys are of the number type. + +**PlainArray** provides the following CRUD APIs. + +| Operation| Description| +| -------- | ------ | +| Adding elements| Use **add(key: number,value: T)** to add an element (a KV pair) to this container.| +| Accessing elements| Use **get(key: number)** to obtain the value of the specified key.| +| Accessing elements| Use **getIndexOfKey(key: number)** to obtain the index of the specified key.| +| Accessing elements| Use **getIndexOfValue(value: T)** to obtain the index of the specified value.| +| Accessing elements| Use **getKeyAt(index: number)** to obtain the key of an element at a given position (specified by **index**).| +| Accessing elements| Use **getValueAt(index: number)** to obtain the value of an element at a given position (specified by **index**).| +| Accessing elements| Use **forEach(callbackFn: (value: T, index?: number, PlainArray?: PlainArray) => void, thisArg?: Object)** to traverse the elements in this container.| +| Accessing elements| Use **\[Symbol.iterator]():IterableIterator<[number, T]>** for data access.| +| Modifying elements| Use **setValueAt(index:number, value: T)** to change the value of an element at a given position (specified by **index**).| +| Modifying elements| Use **forEach(callbackFn: (value: T, index?: number, PlainArray?: PlainArray) => void, thisArg?: Object)** to modify an element in this container.| +| Deleting elements| Use **remove(key: number)** to remove an element with the specified key.| +| Deleting elements| Use **removeAt(index: number)** to remove an element at a given position (specified by **index**).| +| Deleting elements| Use **removeRangeFrom(index: number, size: number)** to remove elements in a specified range.| +| Deleting elements| Use **clear()** to clear this container.| + + +## Use of Nonlinear Containers + +Refer to the code snippet below to add, access, and modify elements in **HashMap**, **TreeMap**, **LightWeightMap**, **Stack**, and **PlainArray**. + + +```js +// HashMap +import HashMap from '@ohos.util.HashMap'; // Import the HashMap module. + +let hashMap = new HashMap(); +hashMap.set('a', 123); +hashMap.set (4, 123);// Add an element. +console.info(`result: ${hashMap.hasKey(4)}`); // Check whether an element is contained. +console.info(`result: ${hashMap.get('a')}`); // Access an element. + +// TreeMap +import TreeMap from '@ohos.util.TreeMap'; // Import the TreeMap module. + +let treeMap = new TreeMap(); +treeMap.set('a', 123); +treeMap.set('6', 356); // Add an element. +console.info(`result: ${treeMap.get('a')}`); // Access an element. +console.info(`result: ${treeMap.getFirstKey()}`); // Access the first element. +console.info(`result: ${treeMap.getLastKey()}`); // Access the last element. + +// LightWeightMap +import LightWeightMap from '@ohos.util.LightWeightMap'; // Import the LightWeightMap module. + +let lightWeightMap = new LightWeightMap(); +lightWeightMap.set('x', 123); +lightWeightMap.set('8', 356); // Add an element. +console.info(`result: ${lightWeightMap.get('a')}`); // Access an element. +console.info(`result: ${lightWeightMap.get('x')}`); // Access an element. +console.info(`result: ${lightWeightMap.getIndexOfKey('8')}`); // Access an element. + +// PlainArray +import PlainArray from '@ohos.util.PlainArray' // Import the PlainArray module. + +let plainArray = new PlainArray(); +plainArray.add(1, 'sdd'); +plainArray.add(2,'sff'); // Add an element. +console.info(`result: ${plainArray.get(1)}`); // Access an element. +console.info(`result: ${plainArray.getKeyAt(1)}`); // Access an element. +``` diff --git a/en/application-dev/arkts-utils/single-io-development.md b/en/application-dev/arkts-utils/single-io-development.md new file mode 100644 index 0000000000000000000000000000000000000000..b488890b42c9cb5849077fd1f00815f1a3f5ddf8 --- /dev/null +++ b/en/application-dev/arkts-utils/single-io-development.md @@ -0,0 +1,29 @@ +# Single I/O Task Development + + +Asynchronous concurrency provided by Promise and async/await is applicable to the development of a single I/O task. The following uses the asynchronous concurrency capability to write a file as an example. + + +1. Implement the logic of a single I/O task. + + ```js + import fs from '@ohos.file.fs'; + + async function write(data: string, filePath: string) { + let file = await fs.open(filePath, fs.OpenMode.READ_WRITE); + fs.write(file.fd, data).then((writeLen) => { + fs.close(file); + }).catch((err) => { + console.error(`Failed to write data. Code is ${err.code}, message is ${err.message}`); + }) + } + ``` + +2. Use the asynchronous capability to invoke the single I/O task. For details about how to obtain **filePath** in the example, see [Obtaining Application File Paths](../application-models/application-context-stage.md#obtaining-application-file-paths). + + ```js + let filePath = ...; // Application file path + write('Hello World!', filePath).then(() => { + console.info('Succeeded in writing data.'); + }) + ``` diff --git a/en/application-dev/arkts-utils/sync-task-development.md b/en/application-dev/arkts-utils/sync-task-development.md new file mode 100644 index 0000000000000000000000000000000000000000..8ce4290a5122b30955c94a1e9116c92f53e0ea7b --- /dev/null +++ b/en/application-dev/arkts-utils/sync-task-development.md @@ -0,0 +1,173 @@ +# Synchronous Task Development + + +Synchronous tasks are executed in order among multiple threads. For example, as a synchronization primitive, locks prevent data contention. + + +To implement synchronous tasks, you must consider the collaboration and synchronization between multiple threads and ensure the correctness of data and the correct execution of programs. + +If synchronous tasks are independent of each other, you are advised to use **TaskPool**, since it focuses on single independent tasks. For example, a series of imported static methods or methods implemented in singletons are independent. If synchronous tasks are associated with each other, use **Worker**, for example, methods implemented in class objects (not singleton class objects). + + +## Using TaskPool to Process Independent Synchronous Tasks + +**TaskPool** is recommended for scheduling independent synchronous tasks. Typical synchronous tasks are those using static methods. If a unique handle or class object constructed using a singleton points to multiple tasks and these tasks can be used between different worker threads, you can also use **TaskPool**. + +1. Define a concurrency function that internally calls the synchronous methods. + +2. Create a task, execute the task through **TaskPool**, and perform operations on the asynchronous result. Create a [task](../reference/apis/js-apis-taskpool.md#task) and call [execute()](../reference/apis/js-apis-taskpool.md#taskpoolexecute-1) to execute the task synchronously. + +3. Perform concurrent operations. + +Simulate a singleton class that contains synchronous calls. + + +```ts +// handle.ts code +export default class Handle { + static getInstance() { + // Return a singleton object. + } + + static syncGet() { + // Synchronous getter. + return; + } + + static syncSet(num: number) { + // Synchronous setter. + return; + } +} +``` + +Use **TaskPool** to call the related synchronous methods. + + +```ts +// Index.ets code +import taskpool from '@ohos.taskpool'; +import Handle from './Handle'; // Return a static handle. + +// Step 1: Define a concurrency function that internally calls the synchronous methods. +@Concurrent +function func(num: number) { + // Call the synchronous wait implemented in a static class object. + Handle.syncSet(num); + // Alternatively, call the synchronous wait implemented in a singleton object. + Handle.getInstance().syncGet(); + return true; +} + +// Step 2: Create and execute a task. +async function asyncGet() { + // Create a task and pass in the function func. + let task = new taskpool.Task(func, 1); + // Execute the task and obtain the result res. + let res = await taskpool.execute(task); + // Perform operations on the synchronous result. + console.info(String(res)); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + // Step 3: Perform concurrent operations. + asyncGet(); + }) + } + .width('100%') + .height('100%') + } + } +} +``` + + +## Using Worker to Process Associated Synchronous Tasks + +Use **Worker** when you want to schedule a series of synchronous tasks using the same handle or depending on the same class object. + +1. Create a **Worker** object in the main thread and receive messages from the worker thread. + + ```js + import worker from '@ohos.worker'; + + @Entry + @Component + struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let w = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts'); + w.onmessage = function (d) { + // Receive the result of the worker thread. + } + w.onerror = function (d) { + // Receive error information of the worker thread. + } + // Send a Set message to the worker thread. + w.postMessage({'type': 0, 'data': 'data'}) + // Send a Get message to the worker thread. + w.postMessage({'type': 1}) + // Destroy the worker thread. + w.terminate() + }) + } + .width('100%') + } + .height('100%') + } + } + ``` + +2. Bind the **Worker** object in the worker thread and process the synchronous task logic. + + ```js + // handle.ts code + export default class Handle { + syncGet() { + return; + } + + syncSet(num: number) { + return; + } + } + + // Worker.ts code + import worker, { ThreadWorkerGlobalScope, MessageEvents } from '@ohos.worker'; + import Handle from './handle.ts' // Return a handle. + + var workerPort : ThreadWorkerGlobalScope = worker.workerPort; + + // Handle that cannot be transferred. All operations depend on this handle. + var handler = new Handle() + + // onmessage() logic of the worker thread. + workerPort.onmessage = function(e : MessageEvents) { + switch (e.data.type) { + case 0: + handler.syncSet(e.data.data); + workerPort.postMessage('success set'); + case 1: + handler.syncGet(); + workerPort.postMessage('success get'); + } + } + ``` diff --git a/en/application-dev/arkts-utils/taskpool-vs-worker.md b/en/application-dev/arkts-utils/taskpool-vs-worker.md new file mode 100644 index 0000000000000000000000000000000000000000..4a3dcd0557a3afbdcfba515752eeea5780f872ab --- /dev/null +++ b/en/application-dev/arkts-utils/taskpool-vs-worker.md @@ -0,0 +1,164 @@ +# Comparison Between TaskPool and Worker + +**TaskPool** and **Worker** provide a multithread running environment for applications to process time-consuming computing tasks or resource intensive tasks, preventing these tasks from blocking the main thread. This maximizes system utilization, reduces overall resource consumption, and improves overall system performance. + + +This topic compares **TaskPool** with **Worker** from two aspects: [implementation features](#implementation-feature-comparison) and [use cases](#use-case-comparison). It also describes their operating mechanisms and precautions. + + +## Implementation Feature Comparison + +**Table 1** Comparison between TaskPool and Worker in implementation features + +| Item| TaskPool | Worker | +| -------- | -------- | -------- | +| Memory model| Threads are isolated from each other, and memory is not shared.| Threads are isolated from each other, and memory is not shared.| +| Parameter passing mechanism| The structured clone algorithm is used for serialization and deserialization.
ArrayBuffer and SharedArrayBuffer are used for parameter passing and sharing.| The structured clone algorithm is used for serialization and deserialization.
ArrayBuffer and SharedArrayBuffer are used for parameter passing and sharing.| +| Parameter passing| Parameters are directly passed in, without being encapsulated.| Only one parameter can be carried in a message object. Therefore, you must encapsulate excess parameters.| +| Method invocation| Methods are directly passed in and called.| Messages are passed in the worker thread and the corresponding methods are called.| +| Return value| A value is returned by default after asynchronous calling.| Messages proactively sent must be parsed and assigned by calling **onmessage()**.| +| Lifecycle| The task pool manages its own lifecycle, without considering the load.| You are required to manage the number and lifecycle of worker threads.| +| Maximum number of task pools| The number is automatically managed, rather than being manually configured.| A maximum of eight worker threads are supported.| +| Maximum task execution duration| 3 minutes (excluding the time used for Promise or async/await asynchronous call, for example, the time consumed by I/O tasks such as network download and file read/write)| There is no restriction.| +| Task priority setting| Setting the task priority is supported.| Setting the task priority is not supported.| +| Task cancellation| Tasks that have been initiated can be canceled.| Tasks that have been initiated cannot be canceled.| + + +## Use Case Comparison + +Both **TaskPool** and **Worker** support multithread concurrency. **TaskPool** worker threads are bound to the system scheduling priority and support load balancing (automatic scaling). **Worker** threads are manually created and do not support scheduling priority setting. Therefore, **TaskPool** provides better performance than **Worker** and is recommended in most scenarios. + +**TaskPool** is oriented to thread-level independent tasks, and tasks running for more than 3 minutes are automatically reclaimed by the system. **Worker** is oriented to threads and supports thread execution for a long time. + +Common use cases are as follows: + +- Use **Worker** for a task that runs for more than 3 minutes (excluding the time used for Promise or async/await asynchronous call, for example, I/O tasks such as network download and file read/write). For example, use **Worker** for a 1-hour prediction algorithm training job in the background. + +- Use **Worker** for a series of associated synchronous tasks. For example, use **Worker** for a series of database operations, since the same handle is required. + +- Use **TaskPool** for a task for which the priority needs to be set. For example, in the histogram rendering scenario in Gallery, histogram data calculated in the background is used for UI display on the foreground. This requires high-priority processing. In this case, use **TaskPool**. + +- Use **TaskPool** for a task that needs to be canceled frequently. For example, in the large image browsing scenario in Gallery, both images on the left and right sides of the current image are cached. When the user slides to the next image, a cache task on one side needs to be canceled. In this case, use **TaskPool**. + +- Use **TaskPool** for a large number of tasks or tasks with scattered scheduling points. For example, a large-scale application with multiple modules has multiple time-consuming tasks, and it is inconvenient to use eight worker threads to manage load. In this case, **TaskPool** is recommended. + + +## TaskPool Operating Mechanism + +**Figure 1** TaskPool operating mechanism + +![taskpool](figures/taskpool.png) + +With **TaskPool**, you can encapsulate tasks in the main thread and throw the tasks to the task queue. The system selects proper worker threads to distribute and execute the tasks, and then returns the result to the main thread. **TaskPool** provides APIs to execute and cancel tasks, and set the task priority. It also minimizes system resource usage through unified thread management, dynamic scheduling, and load balancing algorithms. By default, the system starts a worker thread and increases the thread quantity as the number of tasks increases. The maximum number of worker threads that can be created depends on the number of physical cores of the device. The formula is max(3, Number of physical cores – 1). If no task is distributed for a long period of time, the system reduces the number of worker threads. + + +## Worker Operating Mechanism + +**Figure 2** Worker operating mechanism + +![worker](figures/worker.png) + +The thread that creates the worker thread is referred to as the host thread (not necessarily the main thread, since a worker thread can also create a worker subthread). A worker thread is also named an actor thread. Each worker thread has an independent instance from the host thread, including the infrastructure, object, and code segment. The worker thread communicates with the host thread by means of message exchange. They use the serialization technique to exchange commands and data. + + +## Precautions for TaskPool + +- A task function must be decorated with **\@Concurrent** and can be used only in .ets files. + +- A task function must be a common function or async function, but not a class member function or anonymous function. + +- A task function can use imported variables and input parameter variables only in a project created on the stage model. In a project created on the FA model, it can use input parameter variables only. + +- A task function in the **TaskPool** worker thread must finish the execution within 3 minutes (excluding the time used for Promise or async/await asynchronous call, for example, the duration of I/O tasks such as network download and file read/write). Otherwise, it forcibly exits. + +- Input parameter types in a task function must be those supported by serialization. For details, see [Common Objects](multi-thread-concurrency-overview.md#common-objects). + +- Parameters of the ArrayBuffer type are transferred in **TaskPool** by default. You can set the transfer list by calling [setTransferList()](../reference/apis/js-apis-taskpool.md#settransferlist10). + +- The context objects in different threads are different. Therefore, **TaskPool** worker threads can use only thread-safe libraries, rather than UI-related non-thread-safe libraries. + +- A maximum of 16 MB data can be serialized. + + +## Precautions for Worker + +- The rules for passing in the **Worker.ts** path during the worker creation vary in different API versions. For details, see [Precautions for File Paths](#precautions-for-file-paths). + +- After a worker thread is created, you must manually manage its lifecycle. A maximum of eight worker threads can run simultaneously. For details, see [Lifecycle Precautions](#lifecycle-precautions). + +- Modules of the [ability type](../quick-start/application-package-structure-stage.md) support **Worker**, but modules of the [library type](../quick-start/application-package-structure-stage.md) do not support **Worker**. + +- When creating a worker thread, the **Worker.ts** file of another module cannot be used. This means that a worker cannot be called across modules. + +- The context objects in different threads are different. Therefore, **Worker** threads can use only thread-safe libraries, rather than UI-related non-thread-safe libraries. + +- A maximum of 16 MB data can be serialized. + + +### Precautions for File Paths + +Before calling an API of the **Worker** module, you must create a **Worker** instance. The constructor function varies in different API versions. + +```js +// Use the following function in API version 9 and later versions: +const worker1 = new worker.ThreadWorker(scriptURL); +// Use the following function in API version 8 and earlier versions: +const worker1 = new worker.Worker(scriptURL); +``` + +The **Worker.ts** file path (specified by **scriptURL**) must be passed in the constructor function. By default, the **workers** directory (upper-level directory of the **Worker.ts** file) is at the same level as the **pages** directory. + +**Stage Model** + + +The following is an example of **scriptURL** in the constructor function: + +```js +// Method 1 +// In the stage model, the workers directory is at the same level as the pages directory in the entry module. +const worker1 = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts', {name:"first worker in Stage model"}); +// In the stage model, the workers directory is a child directory of the pages directory in the entry module. +const worker2 = new worker.ThreadWorker('entry/ets/pages/workers/MyWorker.ts'); + +// Method 2 +// In the stage model, the workers directory is at the same level as the pages directory in the entry module, and bundlename is com.example.workerdemo. +const worker3 = new worker.ThreadWorker('@bundle:com.example.workerdemo/entry/ets/workers/worker'); +// In the stage model, the workers directory is a child directory of the pages directory in the entry module, and bundlename is com.example.workerdemo. +const worker4 = new worker.ThreadWorker('@bundle:com.example.workerdemo/entry/ets/pages/workers/worker'); +``` + + +- Based on the directory structure of the stage model project, the field meanings in method 1 are as follows: + - **entry**: value of the **name** attribute under **module** in the **module.json5** file. + - **ets**: directory for storing the ArkTS source code. It is fixed. + - **workers/MyWorker.ts**: path of the worker source file in the **ets** directory. + +- Based on the directory structure of the stage model project, the field meanings in method 2 are as follows: + - **\@bundle**: fixed label. + - **bundlename**: bundle name of the current application. + - **entryname**: value of the **name** attribute under **module** in the **module.json5** file. + - **ets**: directory for storing the ArkTS source code. It is fixed. + - **workerdir/workerfile**: path of the worker source file in the **ets** directory. + + +**FA Model** + + +The following is an example of **scriptURL** in the constructor function: + +```js +// In the FA model, the workers directory is at the same level as the pages directory in the entry module. +const worker1 = new worker.ThreadWorker('workers/worker.js', {name:'first worker in FA model'}); +// In the FA model, the workers directory is at the same level as the parent directory of the pages directory in the entry module. +const worker2 = new worker.ThreadWorker('../workers/worker.js'); +``` + + +### Lifecycle Precautions + +- Creating and terminating worker threads consume performance. Therefore, you are advised to manage available workers and reuse them. The worker threads keep running even when they are idle. Therefore, when a worker thread is not required, call [terminate()](../reference/apis/js-apis-worker.md#terminate9) interface or [parentPort.close()](../reference/apis/js-apis-worker.md#close9) to destroy it. If a worker thread is destroyed or being destroyed, an error is thrown when it is called. + + +- A maximum of eight worker threads can co-exist. + - In API version 8 and earlier versions, when the number of worker threads exceeds the upper limit, the error "Too many workers, the number of workers exceeds the maximum." is thrown. + - Since API version 9, when the number of worker threads exceeds the upper limit, the error "Worker initialization failure, the number of workers exceeds the maximum." is thrown. diff --git a/en/application-dev/arkts-utils/xml-conversion.md b/en/application-dev/arkts-utils/xml-conversion.md new file mode 100644 index 0000000000000000000000000000000000000000..96dc727635ea4449edd3bdc41e5ec016b268eca9 --- /dev/null +++ b/en/application-dev/arkts-utils/xml-conversion.md @@ -0,0 +1,92 @@ +# XML Conversion + + +Converting XML text into JavaScript objects makes it easier to process and manipulate data. In addition, JavaScript objects are more suitable than XML text for JavaScript applications. + + +The common library provides the **ConvertXML** class to convert XML text into JavaScript objects. The input is XML strings and conversion options, and the output is a JavaScript object. For details about the conversion options, see the API reference [@ohos.convertxml (XML-to-JavaScript Conversion)](../reference/apis/js-apis-convertxml.md). + + +## Precautions + +To ensure successful XML parsing and conversion, the input XML data must comply with the standard format. + + +## How to Develop + +The following steps walk you through on how to convert an XML file into a JavaScript object to obtain the tag values. + +1. Import the **convertxml** module. + + ```js + import convertxml from '@ohos.convertxml'; + ``` + +2. Pass in an XML file to be converted and set conversion options. + + ```js + let xml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; + let options = { + // trim: false, indicating that spaces before and after the text are not deleted after conversion. + // declarationKey: "_declaration", indicating that _declaration is used to identify the file declaration after conversion. + // instructionKey: "_instruction", indicating that _instruction is used to identify instructions after conversion. + // attributesKey: "_attributes", indicating that _attributes is used to identify attributes after conversion. + // textKey: "_text", indicating that _text is used to identify tag values after conversion. + // cdataKey: "_cdata", indicating that _cdata is used to identify unparsed data after conversion. + // docTypeKey: "_doctype", indicating that _doctype is used to identify documents after conversion. + // commentKey: "_comment", indicating that _comment is used to identify comments after conversion. + // parentKey: "_parent", indicating that _parent is used to identify parent classes after conversion. + // typeKey: "_type", indicating that _type is used to identify types after conversion. + // nameKey: "_name", indicating that _name is used to identify tag names after conversion. + // elementsKey: "_elements", indicating that _elements is used to identify elements after conversion. + trim: false, + declarationKey: "_declaration", + instructionKey: "_instruction", + attributesKey: "_attributes", + textKey: "_text", + cdataKey: "_cdata", + docTypeKey: "_doctype", + commentKey: "_comment", + parentKey: "_parent", + typeKey: "_type", + nameKey: "_name", + elementsKey: "_elements" + } + ``` + +3. Call the conversion function and print the result. + + ```js + let conv = new convertxml.ConvertXML(); + let result = conv.convertToJSObject(xml, options); + let strRes = JSON.stringify(result); // Convert the JavaScript object into a JSON string for explicit output. + console.info(strRes); + // Alternatively, directly process the JavaScript object to obtain the tag values. + let title = result['_elements'][0]['_elements'][0]['_elements'][0]['_text']; // Parse the value of the tag. + let todo = result['_elements'][0]['_elements'][1]['_elements'][0]['_text']; // Parse the value of the <todo> tag. + let todo2 = result['_elements'][0]['_elements'][2]['_elements'][0]['_text']; // Parse the value of the <todo> tag. + console.info(title); // Happy + console.info(todo); // Work + console.info(todo2); // Play + ``` + + The output is as follows: + + + ```js + strRes: + {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note", + "_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title", + "_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo", + "_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo", + "_elements":[{"_type":"text","_text":"Play"}]}]}]} + title:Happy + todo:Work + todo2:Play + ``` diff --git a/en/application-dev/arkts-utils/xml-generation.md b/en/application-dev/arkts-utils/xml-generation.md new file mode 100644 index 0000000000000000000000000000000000000000..d05cd9779255c6dfa51a9d4bb4556e2467c92c1c --- /dev/null +++ b/en/application-dev/arkts-utils/xml-generation.md @@ -0,0 +1,82 @@ +# XML Generation + + +XML can be used as a data exchange format, which is supported by a wealth of systems and applications. For example, web services can transfer structured data in XML format. + + +XML can also be used as a message passing format for communication between nodes in a distributed system. + + +## Precautions + +- XML tags must appear in pairs: one start tag and one end tag. + +- XML tags are case sensitive. The start tag and end tag must use the same case. + + +## How to Develop + +The **xml** module provides the **XmlSerializer** class to generate XML files. The input is an object of the ArrayBuffer or DataView type with a fixed length, which is used to store the output XML data. + +You can call different to write different types of content. For example, call **startElement(name: string)** to write the start tag and **setText(text: string)** to write a tag value. + +For details about the APIs of the **XML** module, see [@ohos.xml (XML Parsing and Generation)](../reference/apis/js-apis-xml.md). + +The following steps walk you through on how to generate an XML file. + +1. Import the modules. + + ```js + import xml from '@ohos.xml'; + import util from '@ohos.util'; + ``` + +2. Create a buffer and create an **XmlSerializer** object, either based on an object of the ArrayBuffer or DataView type. + + ```js + // 1. Create an XmlSerializer object based on an object of the ArrayBuffer type. + let arrayBuffer = new ArrayBuffer(2048); // Create a 2048-byte object of the ArrayBuffer type. + let thatSer = new xml.XmlSerializer (arrayBuffer); // Create an XmlSerializer object based on the object of the ArrayBuffer type. + + // 2. Create an XmlSerializer object based on an object of the DataView type. + let arrayBuffer = new ArrayBuffer(2048); // Create a 2048-byte object of the ArrayBuffer type. + let dataView = new DataView(arrayBuffer); // Use an object of the DataView type to operate the object of the ArrayBuffer type. + let thatSer = new xml.XmlSerializer (dataView); // Create an XmlSerializer object based on the object of the DataView type. + ``` + +3. Call the functions to generate an XML file. + + ```js + thatSer.setDeclaration(); // Write the XML file declaration. + thatSer.startElement('bookstore'); // Write the start flag. + thatSer.startElement('book'); // Write the start tag of a nested element. + thatSer.setAttributes('category', 'COOKING'); // Write the attributes and attribute values. + thatSer.startElement('title'); + thatSer.setAttributes('lang', 'en'); + thatSer.setText('Everyday'); // Write the tag value. + thatSer.endElement(); // Write the end flag. + thatSer.startElement('author'); + thatSer.setText('Giada'); + thatSer.endElement(); + thatSer.startElement('year'); + thatSer.setText('2005'); + thatSer.endElement(); + thatSer.endElement(); + thatSer.endElement(); + ``` + +4. Use **Uint8Array** to operate the object of the ArrayBuffer type, and use **TextDecoder** to decode the Uint8Array. + + ```js + let view = new Uint8Array(arrayBuffer); // Use Uint8Array to read data from the object of the ArrayBuffer type. + let textDecoder = util.TextDecoder.create(); // Call the TextDecoder class of the util module. + let res = textDecoder.decodeWithStream (view); // Decode the view. + console.info(res); + ``` + + The output is as follows: + + + ```js + <?xml version=\"1.0\" encoding=\"utf-8\"?><bookstore>\r\n <book category=\"COOKING\">\r\n <title lang=\"en\">Everyday\r\n Giada\r\n 2005\r\n \r\n + ``` diff --git a/en/application-dev/arkts-utils/xml-overview.md b/en/application-dev/arkts-utils/xml-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..d376fea2134fbdac8a02d5a4c8e4ffdfdb99eb4d --- /dev/null +++ b/en/application-dev/arkts-utils/xml-overview.md @@ -0,0 +1,23 @@ +# XML Overview + + +Extensible Markup Language (XML) is a markup language used to describe data. It aims to provide a common way to transmit and store data, especially data frequently used in web applications. XML does not predefine tags. As a result, it is more flexible and widely used. + + +An XML file consists of elements, attributes, and content. + + +- An element refers to a tag pair that contains text, attributes, or other elements. + +- Attributes provide additional information about an element. + +- Content is the data or sub-element contained in an element. + + +XML supports the use of XML Schema Definition (XSD) or Document Type Definition (DTD) for defining the document structure. This allows you to customize rules to verify whether an XML document is in the expected format. + + +XML also supports features such as namespaces, entity references, comments, and processing instructions, making it easy to adapt to diverse data requirements. + + +The common library provides XML-related basic capabilities, including [XML generation](xml-generation.md), [XML parsing](xml-parsing.md), and [XML conversion](xml-conversion.md). diff --git a/en/application-dev/arkts-utils/xml-parsing.md b/en/application-dev/arkts-utils/xml-parsing.md new file mode 100644 index 0000000000000000000000000000000000000000..dd3e46517b3eec6aafce6d6566a2da982bbd8d6c --- /dev/null +++ b/en/application-dev/arkts-utils/xml-parsing.md @@ -0,0 +1,271 @@ +# XML Parsing + + +Data transferred in XML format must be parsed in actual use. Generally, three types of elements need to be parsed, as described in [Parsing XML Tags and Tag Values](#parsing-xml-tags-and-tag-values), [Parsing XML Attributes and Attribute Values](#parsing-xml-attributes-and-attribute-values), and [Parsing XML Event Types and Element Depths](#parsing-xml-event-types-and-element-depths). + + +The **xml** module provides the **XmlPullParser** class to parse XML files. The input is an object of the ArrayBufffer or DataView type containing XML text, and the output is the parsed information. + + +**Table 1** XML parsing options + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| supportDoctype | boolean | No| Whether to ignore the document type. The default value is **false**, indicating that the document type is parsed.| +| ignoreNameSpace | boolean | No| Whether to ignore the namespace. The default value is **false**, indicating that the namespace is parsed.| +| tagValueCallbackFunction | (name: string, value: string) => boolean | No| Callback used to return **tagValue**, which consists of a tag and its value. The default value is **null**, indicating that XML tags and tag values are not parsed.| +| attributeValueCallbackFunction | (name: string, value: string) => boolean | No| Callback used to return **attributeValue**, which consists of an attribute and its value. The default value is **null**, indicating that XML attributes and attribute values are not parsed.| +| tokenValueCallbackFunction | (eventType: EventType, value: ParseInfo) => boolean | No| Callback used to return **tokenValue**, which consists of the event type and the attributes of **parseInfo**. The default value is **null**, indicating that the event type and the attributes of **parseInfo** are not parsed.| + + +## Precautions + +- To ensure successful XML parsing and conversion, the input XML data must comply with the standard format. + +- Currently, parsing a given node is not supported. + + +## Parsing XML Tags and Tag Values + +1. Import the modules. + + ```js + import xml from '@ohos.xml'; + import util from '@ohos.util'; // Use the API provided by the util module to encode the file. + ``` + +2. Create an **XmlPullParser** object. + + The **XmlPullParser** object can be created based on an object of the ArrayBuffer or DataView type. + + + ```js + let strXml = + '' + + '' + + 'Play' + + 'Work' + + ''; + let textEncoder = new util.TextEncoder(); + let arrBuffer = textEncoder.encodeInto(strXml); // Encode the data to prevent garbled characters. + // 1. Create an XmlPullParser object based on an object of the ArrayBuffer type. + let that = new xml.XmlPullParser(arrBuffer.buffer, 'UTF-8'); + + // 2. Create an XmlPullParser object based on an object of the DataView type. + let dataView = new DataView(arrBuffer.buffer); + let that = new xml.XmlPullParser(dataView, 'UTF-8'); + ``` + +3. Customize a callback function. In this example, the tag and tag value are directly printed. + + ```js + let str = ''; + function func(name, value){ + str = name + value; + console.info(str); + return true; // The value true means to continue parsing, and false means to stop parsing. + } + ``` + +4. Set parsing options and call the **parse()** function. + + ```js + let options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func}; + that.parse(options); + ``` + + The output is as follows: + + + ```js + note + title + Play + title + lens + Work + lens + note + ``` + + +## Parsing XML Attributes and Attribute Values + +1. Import the modules. + + ```js + import xml from '@ohos.xml'; + import util from '@ohos.util'; // Use the API provided by the util module to encode the file. + ``` + +2. Create an **XmlPullParser** object. + + ```js + let strXml = + '' + + '' + + ' Play' + + ' Happy' + + ' Work' + + ''; + let textEncoder = new util.TextEncoder(); + let arrBuffer = textEncoder.encodeInto(strXml); // Encode the data to prevent garbled characters. + let that = new xml.XmlPullParser(arrBuffer.buffer, 'UTF-8'); + ``` + +3. Customize a callback function. In this example, the attribute and attribute value are directly printed. + + ```js + let str = ''; + function func(name, value){ + str += name + ' ' + value + ' '; + return true; // The value true means to continue parsing, and false means to stop parsing. + } + ``` + +4. Set parsing options and call the **parse()** function. + + ```js + let options = {supportDoctype:true, ignoreNameSpace:true, attributeValueCallbackFunction:func}; + that.parse(options); + console.info(str); // Print all attributes and their values at a time. + ``` + + The output is as follows: + + + ```js + importance high logged true // Attributes and attribute values of the note node + ``` + + +## Parsing XML Event Types and Element Depths + +1. Import the modules. + + ```js + import xml from '@ohos.xml'; + import util from '@ohos.util'; // Use the API provided by the util module to encode the file. + ``` + +2. Create an **XmlPullParser** object. + + ```js + let strXml = + '' + + '' + + 'Play' + + ''; + let textEncoder = new util.TextEncoder(); + let arrBuffer = textEncoder.encodeInto(strXml); // Encode the data to prevent garbled characters. + let that = new xml.XmlPullParser(arrBuffer.buffer, 'UTF-8'); + ``` + +3. Customize a callback function. In this example, the event type and element depth are directly printed. + + ```js + let str = ''; + function func(name, value){ + str = name +' ' + value.getDepth(); // getDepth is called to obtain the element depth. + console.info(str) + return true; // The value true means to continue parsing, and false means to stop parsing. + } + ``` + +4. Set parsing options and call the **parse()** function. + + ```js + let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}; + that.parse(options); + ``` + + The output is as follows: + + + ```js + 0 0 // 0: . The event type value of START_DOCUMENT is 0. 0: The depth is 0. + 2 1 // 2: . The event type value of START_TAG is 2. 1: The depth is 1. + 2 2 // 2: . The event type value of START_TAG is 2. 2: The depth is 2. + 4 2 // 4: Play. The event type value of TEXT is 4. 2: The depth is 2. + 3 2 // 3: . The event type value of END_TAG is 3. 2: The depth is 2. + 3 1 // 3: . The event type value of END_TAG is 3. 1: The depth is 1 (corresponding to ). + 1 0 // 1: The event type value of END_DOCUMENT is 1. 0: The depth is 0. + ``` + + +## Example Scenario + +The following uses invoking all parsing options as an example to describe how to parse XML tags, attributes, and event types. + + +```js +import xml from '@ohos.xml'; +import util from '@ohos.util'; + +let strXml = + '' + + '' + + 'Everyday' + + 'Giada' + + ''; +let textEncoder = new util.TextEncoder(); +let arrBuffer = textEncoder.encodeInto(strXml); +let that = new xml.XmlPullParser(arrBuffer.buffer, 'UTF-8'); +let str = ''; + +function tagFunc(name, value) { + str = name + value; + console.info('tag-' + str); + return true; +} + +function attFunc(name, value) { + str = name + ' ' + value; + console.info('attri-' + str); + return true; +} + +function tokenFunc(name, value) { + str = name + ' ' + value.getDepth(); + console.info('token-' + str); + return true; +} + +let options = { + supportDocType: true, + ignoreNameSpace: true, + tagValueCallbackFunction: tagFunc, + attributeValueCallbackFunction: attFunc, + tokenValueCallbackFunction: tokenFunc +}; +that.parse(options); + +``` + +The output is as follows: + + +```js +tag- +token-0 0 +tag-book +attri-category COOKING +token-2 1 +tag-title +attri-lang en +token-2 2 +tag-Everyday +token-4 2 +tag-title +token-3 2 +tag-author +token-2 2 +tag-Giada +token-4 2 +tag-author +token-3 2 +tag-book +token-3 1 +tag- +token-1 0 +``` diff --git a/en/application-dev/reference/apis/js-apis-hashmap.md b/en/application-dev/reference/apis/js-apis-hashmap.md index fc0a1e56470f7fb3a66a5feb1ad168b2c0fcea4a..330c9c423c6f4c080c30d017b78aaf99bc4d2104 100644 --- a/en/application-dev/reference/apis/js-apis-hashmap.md +++ b/en/application-dev/reference/apis/js-apis-hashmap.md @@ -338,7 +338,7 @@ hashMap.clear(); keys(): IterableIterator<K> -Obtains an iterator that contains all the elements in this container. +Obtains an iterator that contains all the keys in this container. **System capability**: SystemCapability.Utils.Lang diff --git a/en/application-dev/reference/apis/js-apis-treemap.md b/en/application-dev/reference/apis/js-apis-treemap.md index 38f3d0525c9d7a35b33a808e0ae8fd38ea58bf4d..7266c6f98219a965bd70235747191e710fedb224 100644 --- a/en/application-dev/reference/apis/js-apis-treemap.md +++ b/en/application-dev/reference/apis/js-apis-treemap.md @@ -4,7 +4,7 @@ **TreeMap** is implemented using a red-black tree, which is a binary search tree where keys are stored in sorted order for efficient insertion and removal. -**[HashMap](js-apis-treemap.md)** is faster in accessing data than **TreeMap**, because the former accesses data based on the hash code of the key, whereas the latter stores and accesses the keys in sorted order. +**[HashMap](js-apis-hashmap.md)** is faster in accessing data than **TreeMap**, because the former accesses data based on the hash code of the key, whereas the latter stores and accesses the keys in sorted order. Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order. diff --git a/en/application-dev/reference/apis/js-apis-worker.md b/en/application-dev/reference/apis/js-apis-worker.md index 6d1bff42d490701f87940606d1ae4332b339b260..59111203ed8ea233dcb6d579a869a258fb251f5a 100644 --- a/en/application-dev/reference/apis/js-apis-worker.md +++ b/en/application-dev/reference/apis/js-apis-worker.md @@ -89,7 +89,7 @@ const workerFAModel02 = new worker.ThreadWorker("../workers/worker.ts"); // In the stage model, the workers directory is at the same level as the pages directory in the entry module. const workerStageModel01 = new worker.ThreadWorker('entry/ets/workers/worker.ts', {name:"first worker in Stage model"}); -// In the stage model, the workers directory is at the same level as the parent directory of the pages directory in the entry module. +// In the stage model, the workers directory is a child directory of the pages directory in the entry module. const workerStageModel02 = new worker.ThreadWorker('entry/ets/pages/workers/worker.ts'); // For the script URL "entry/ets/workers/worker.ts" in the stage model: @@ -101,7 +101,7 @@ const workerStageModel02 = new worker.ThreadWorker('entry/ets/pages/workers/work // workerdir indicates the directory where the worker file is located, and workerfile indicates the worker file name. // In the stage model, the workers directory is at the same level as the pages directory in the entry module, and bundlename is com.example.workerdemo. const workerStageModel03 = new worker.ThreadWorker('@bundle:com.example.workerdemo/entry/ets/workers/worker'); -// In the stage model, the workers directory is at the same level as the parent directory of the pages directory in the entry module, and bundlename is com.example.workerdemo. +// In the stage model, the workers directory is a child directory of the pages directory in the entry module, and bundlename is com.example.workerdemo. const workerStageModel04 = new worker.ThreadWorker('@bundle:com.example.workerdemo/entry/ets/pages/workers/worker'); ``` @@ -1199,7 +1199,7 @@ const workerFAModel02 = new worker.Worker("../workers/worker.ts"); // In the stage model, the workers directory is at the same level as the pages directory. const workerStageModel01 = new worker.Worker('entry/ets/workers/worker.ts', {name:"first worker in Stage model"}); -// In the stage model, the workers directory is at the same level as the child directory of the pages directory. +// In the stage model, the workers directory is a child directory of the pages directory. const workerStageModel02 = new worker.Worker('entry/ets/pages/workers/worker.ts'); // For the script URL "entry/ets/workers/worker.ts" in the stage model: @@ -2027,18 +2027,8 @@ parentPort.onerror = function(e){ ## More Information ### Sequenceable Data Types -| Type | Remarks | Supported| -| ------------------ | -------------------------------------- | -------- | -| All primitive types| The Symbol type is not included. | Yes | -| Date | | Yes | -| String | | Yes | -| RegExp | | Yes | -| Array | | Yes | -| Map | | Yes | -| Set | | Yes | -| Object | Only plain objects are supported. Objects with functions are not supported.| Yes | -| ArrayBuffer | The transfer capability is provided. | Yes | -| TypedArray | | Yes | + +The following object types are supported: basic types except Symbol, Date, String, RegExp, Array, Map, Set, Object (simple objects only, for example, objects created using **{}** or **new Object**), ArrayBuffer, and typedArray. (Note that only attributes can be transferred for common objects. Prototypes and methods cannot be transferred.) Exception: When an object created through a custom class is passed, no serialization error occurs. However, the attributes (such as Function) of the custom class cannot be passed through serialization. > **NOTE**
@@ -2096,7 +2086,7 @@ The worker thread is implemented based on the actor model. In the worker interac Each actor concurrently processes tasks of the main thread. For each actor, there is a message queue and a single-thread execution module. The message queue receives requests from the main thread and other actors; the single-thread execution module serially processes requests, sends requests to other actors, and creates new actors. These isolated actors use the asynchronous mode and can run concurrently. ### Precautions -- Currently, a maximum of eight workers can co-exist. +- Currently, a maximum of eight worker threads can co-exist. - In API version 8 and earlier versions, when the number of **Worker** instances exceeds the upper limit, the error "Too many workers, the number of workers exceeds the maximum." is thrown. - Since API version 9, when the number of **Worker** instances exceeds the upper limit, the business error "Worker initialization failure, the number of workers exceeds the maximum." is thrown. - To proactively destroy a worker thread, you can call **terminate()** or **parentPort.close()** of the newly created **Worker** instance. diff --git a/en/application-dev/website.md b/en/application-dev/website.md index 95270ecc2aaf739d7a6f5f6efb091eeedb97a98c..e37750a58dd8a412da91f2c08afc89614ccf59d2 100644 --- a/en/application-dev/website.md +++ b/en/application-dev/website.md @@ -54,6 +54,7 @@ - [\@Styles Decorator: Definition of Resusable Styles](quick-start/arkts-style.md) - [\@Extend Decorator: Extension of Built-in Components](quick-start/arkts-extend.md) - [stateStyles: Polymorphic Style](quick-start/arkts-statestyles.md) + - [\@AnimatableExtend Decorator: Definition of Animatable Attributes](quick-start/arkts-animatable-extend.md) - State Management - [State Management Overview](quick-start/arkts-state-management-overview.md) - Component State Management @@ -100,6 +101,7 @@ - [EnterpriseAdminExtensionAbility](application-models/enterprise-extensionAbility.md) - [InputMethodExtensionAbility](application-models/inputmethodextentionability.md) - [WindowExtensionAbility (for System Applications Only)](application-models/windowextensionability.md) + - [DriverExtensionAbility](application-models/driverextensionability.md) - Service Widget Development in Stage Model - [Service Widget Overview](application-models/service-widget-overview.md) - Developing an ArkTS Widget @@ -375,6 +377,27 @@ - [Animation Effect](ui/ui-js-animate-dynamic-effects.md) - [Animation Frame](ui/ui-js-animate-frame.md) - [Custom Components](ui/ui-js-custom-components.md) + - ArkTS Common Library + - [Overview of ArkTS Common Library](arkts-utils/arkts-commonlibrary-overview.md) + - Concurrency + - [Concurrency Overview](arkts-utils/concurrency-overview.md) + - Using Asynchronous Concurrency for Development + - [Asynchronous Concurrency Overview](arkts-utils/async-concurrency-overview.md) + - [Single I/O Task Development](arkts-utils/single-io-development.md) + - Using Multithread Concurrency for Development + - [Comparison Between TaskPool and Worker](arkts-utils/taskpool-vs-worker.md) + - [CPU Intensive Task Development](arkts-utils/cpu-intensive-task-development.md) + - [I/O Intensive Task Development](arkts-utils/io-intensive-task-development.md) + - [Synchronous Task Development](arkts-utils/sync-task-development.md) + - Container + - [Container Overview](arkts-utils/container-overview.md) + - [Linear Containers](arkts-utils/linear-container.md) + - [Nonlinear Containers](arkts-utils/nonlinear-container.md) + - XML Generation, Parsing, and Conversion + - [XML Overview](arkts-utils/xml-overview.md) + - [XML Generation](arkts-utils/xml-generation.md) + - [XML Parsing](arkts-utils/xml-parsing.md) + - [XML Conversion](arkts-utils/xml-conversion.md) - Web - [Web Component Overview](web/web-component-overview.md) - [Loading Pages by Using the Web Component](web/web-page-loading-with-web-components.md) @@ -419,6 +442,7 @@ - [Using AudioRenderer for Audio Playback](media/using-audiorenderer-for-playback.md) - [Using OpenSL ES for Audio Playback](media/using-opensl-es-for-playback.md) - [Using TonePlayer for Audio Playback (for System Applications Only)](media/using-toneplayer-for-playback.md) + - [Using OHAudio for Audio Playback](media/using-ohaudio-for-playback.md) - [Audio Playback Concurrency Policy](media/audio-playback-concurrency.md) - [Volume Management](media/volume-management.md) - [Audio Effect Management](media/audio-effect-management.md) @@ -430,6 +454,7 @@ - [Using AVRecorder for Audio Recording](media/using-avrecorder-for-recording.md) - [Using AudioCapturer for Audio Recording](media/using-audiocapturer-for-recording.md) - [Using OpenSL ES for Audio Recording](media/using-opensl-es-for-recording.md) + - [Using OHAudio for Audio Recording](media/using-ohaudio-for-recording.md) - [Microphone Management](media/mic-management.md) - [Audio Recording Stream Management](media/audio-recording-stream-management.md) - [Audio Input Device Management](media/audio-input-device-management.md) @@ -438,6 +463,14 @@ - [Developing Audio Call](media/audio-call-development.md) - [Video Playback](media/video-playback.md) - [Video Recording](media/video-recording.md) + - Audio and Video Codecs + - [Obtaining Supported Codecs](media/obtain-supported-codecs.md) + - [Audio Encoding](media/audio-encoding.md) + - [Audio Decoding](media/audio-decoding.md) + - [Video Encoding](media/video-encoding.md) + - [Video Decoding](media/video-decoding.md) + - [Audio/Video Encapsulation](media/audio-video-encapsulation.md) + - [Audio/Video Decapsulation](media/audio-video-decapsulation.md) - AVSession - [AVSession Overview](media/avsession-overview.md) - Local AVSession @@ -475,12 +508,14 @@ - [Applying for Permissions](security/accesstoken-guidelines.md) - [Verifying API Access Permissions](security/permission-verify-guidelines.md) - [Application Permission List](security/permission-list.md) + - [Application Permission Group List](security/permission-group-list.md) - User Authentication - [User Authentication Overview](security/userauth-overview.md) - [User Authentication Development](security/userauth-guidelines.md) - HUKS - [HUKS Overview](security/huks-overview.md) - - [HUKS Development](security/huks-guidelines.md) + - [HUKS Development (ArkTS)](security/huks-guidelines.md) + - [HUKS Development (Native)](security/native-huks-guidelines.md) - [HUKS Cipher Algorithm Specifications](security/huks-appendix.md) - Crypto Framework - [Crypto Framework Overview](security/cryptoFramework-overview.md) @@ -553,6 +588,12 @@ - Selecting and Saving User Files (FilePicker) - [Selecting User Files](file-management/select-user-file.md) - [Saving User Files](file-management/save-user-file.md) + - Album Management (photoAccessHelper) + - [photoAccessHelper Overview](file-management/photoAccessHelper-overview.md) + - [Media Asset (Image and video) Management](file-management/photoAccessHelper-resource-guidelines.md) + - [User Album Management](file-management/photoAccessHelper-userAlbum-guidelines.md) + - [System Album Management](file-management/photoAccessHelper-systemAlbum-guidelines.md) + - [Media Asset Change Notification Management](file-management/photoAccessHelper-notify-guidelines.md) - [Developing a FileManager Application (for System Applications Only)](file-management/dev-user-file-manager.md) - [Managing External Storage Devices (for System Applications Only)](file-management/manage-external-storage.md) - Distributed File System @@ -590,6 +631,8 @@ - [Sample Server Development](device/sample-server-guidelines.md) - Stationary - [Stationary Development](device/stationary-guidelines.md) + - Peripheral + - [Peripheral Management Development](device/externaldevice-guidelines.md) - Device Usage Statistics - [Device Usage Statistics Overview](device-usage-statistics/device-usage-statistics-overview.md) - [Device Usage Statistics Development](device-usage-statistics/device-usage-statistics-use-guide.md) @@ -599,6 +642,7 @@ - [HiLog Development (Native)](dfx/hilog-guidelines.md) - Performance Tracing - [Development of Performance Tracing (ArkTS)](dfx/hitracemeter-guidelines.md) + - [Development of Performance Tracing (Native)](dfx/hitracemeter-native-guidelines.md) - Error Management - [Development of Error Manager](dfx/errormanager-guidelines.md) - [Development of Application Recovery](dfx/apprecovery-guidelines.md) @@ -616,13 +660,21 @@ - [IDL Specifications and User Guide](IDL/idl-guidelines.md) - Native APIs - [Using Native APIs in Application Projects](napi/napi-guidelines.md) - - [Drawing Development](napi/drawing-guidelines.md) - - [Raw File Development](napi/rawfile-guidelines.md) - - [Native Window Development](napi/native-window-guidelines.md) - - [Using MindSpore Lite for Model Inference](napi/mindspore-lite-guidelines.md) - - [Using MindSpore Lite for Offline Model Conversion and Inference](napi/mindspore-lite-offline-model-guidelines.md) - - [Connecting the Neural Network Runtime to an AI Inference Framework](napi/neural-network-runtime-guidelines.md) - - [Purgeable Memory Development](napi/purgeable-memory-guidelines.md) + - Graphics + - [Drawing Development](napi/drawing-guidelines.md) + - [NativeBuffer Development](napi/native-buffer-guidelines.md) + - [NativeImage Development](napi/native-image-guidelines.md) + - [NativeVsync Development](napi/native-vsync-guidelines.md) + - [NativeWindow Development](napi/native-window-guidelines.md) + - [Vulkan Development](napi/vulkan-guidelines.md) + - Resource Management + - [Raw File Development](napi/rawfile-guidelines.md) + - AI + - [Using MindSpore Lite for Model Inference](napi/mindspore-lite-guidelines.md) + - [Using MindSpore Lite for Offline Model Conversion and Inference](napi/mindspore-lite-offline-model-guidelines.md) + - [Connecting the Neural Network Runtime to an AI Inference Framework](napi/neural-network-runtime-guidelines.md) + - Memory Management + - [Purgeable Memory Development](napi/purgeable-memory-guidelines.md) - Tools - [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md) - Debugging Tools @@ -649,6 +701,7 @@ - [@ohos.app.ability.AbilityConstant (AbilityConstant)](reference/apis/js-apis-app-ability-abilityConstant.md) - [@ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)](reference/apis/js-apis-app-ability-abilityLifecycleCallback.md) - [@ohos.app.ability.AbilityStage (AbilityStage)](reference/apis/js-apis-app-ability-abilityStage.md) + - [@ohos.app.ability.ApplicationStateChangeCallback (ApplicationStateChangeCallback)](reference/apis/js-apis-app-ability-applicationStateChangeCallback.md) - [@ohos.app.ability.common (Context)](reference/apis/js-apis-app-ability-common.md) - [@ohos.app.ability.contextConstant (ContextConstant)](reference/apis/js-apis-app-ability-contextConstant.md) - [@ohos.app.ability.EnvironmentCallback (EnvironmentCallback)](reference/apis/js-apis-app-ability-environmentCallback.md) @@ -791,8 +844,18 @@ - [Common Events of the Bundle Management Subsystem](reference/apis/common_event/commonEvent-bundleManager.md) - [Common Events of the Notification Service](reference/apis/common_event/commonEvent-ans.md) - [Common Events of the Resource Scheduler Subsystem](reference/apis/common_event/commonEvent-resourceschedule.md) + - [Common Events of the Window Management Subsystem](reference/apis/common_event/commonEvent-window.md) + - [Common Events of the Network Management Subsystem](reference/apis/common_event/commonEvent-netmanager.md) + - [Common Events of the SMS Application](reference/apis/common_event/commonEvent-mms.md) - [Common Events of the Telephony Subsystem](reference/apis/common_event/commonEvent-telephony.md) + - [Common Events of the Power Management Subsystem](reference/apis/common_event/commonEvent-powermgr.md) + - [Common Events of the NFC Subsystem](reference/apis/common_event/commonEvent-nfc.md) + - [Common Events of the Wi-Fi Subsystem](reference/apis/common_event/commonEvent-wifi.md) - [Common Events of the USB Subsystem](reference/apis/common_event/commonEvent-usb.md) + - [Common Events of the File Management Subsystem](reference/apis/common_event/commonEvent-filemanagement.md) + - [Common Events of the Theme Framework - Lock Screen](reference/apis/common_event/commonEvent-screenlock.md) + - [Common Events of the Time and Time Zone Subsystem](reference/apis/common_event/commonEvent-time.md) + - [Common Events of the Account Subsystem](reference/apis/common_event/commonEvent-account.md) - Bundle Management - [@ohos.bundle.appControl (appControl)](reference/apis/js-apis-appControl.md) - [@ohos.bundle.bundleManager (bundleManager)](reference/apis/js-apis-bundleManager.md) @@ -826,6 +889,9 @@ - [@ohos.animator (Animator)](reference/apis/js-apis-animator.md) - [@ohos.arkui.componentSnapshot (Component Snapshot)](reference/apis/js-apis-arkui-componentSnapshot.md) - [@ohos.arkui.drawableDescriptor (DrawableDescriptor)](reference/apis/js-apis-arkui-drawableDescriptor.md) + - [@ohos.arkui.inspector (Layout Callback)](reference/apis/js-apis-arkui-inspector.md) + - [@ohos.arkui.UIContext (UIContext)](reference/apis/js-apis-arkui-UIContext.md) + - [@ohos.componentUtils (componentUtils)](reference/apis/js-apis-componentUtils.md) - [@ohos.curves (Interpolation Calculation)](reference/apis/js-apis-curve.md) - [@ohos.font (Custom Font Registration)](reference/apis/js-apis-font.md) - [@ohos.matrix4 (Matrix Transformation)](reference/apis/js-apis-matrix4.md) @@ -893,6 +959,7 @@ - [@ohos.data.ValuesBucket (Value Bucket)](reference/apis/js-apis-data-valuesBucket.md) - File Management - [@ohos.file.backup (Backup and Restoration)](reference/apis/js-apis-file-backup.md) + - [@ohos.file.cloudSync (Device-Cloud Synchronization)](reference/apis/js-apis-file-cloudsync.md) - [@ohos.file.cloudSyncManager (Device-Cloud Synchronization Management)](reference/apis/js-apis-file-cloudsyncmanager.md) - [@ohos.file.environment (Directory Environment Capability)](reference/apis/js-apis-file-environment.md) - [@ohos.file.fileAccess (User File Access and Management)](reference/apis/js-apis-fileAccess.md) @@ -901,12 +968,15 @@ - [@ohos.file.fs (File Management)](reference/apis/js-apis-file-fs.md) - [@ohos.file.hash (File Hash Processing)](reference/apis/js-apis-file-hash.md) - [@ohos.file.picker (File Picker)](reference/apis/js-apis-file-picker.md) + - [@ohos.file.photoAccessHelper (Album Management)](reference/apis/js-apis-photoAccessHelper.md) - [@ohos.file.securityLabel (Data Label)](reference/apis/js-apis-file-securityLabel.md) - [@ohos.file.statvfs (File System Space Statistics)](reference/apis/js-apis-file-statvfs.md) - [@ohos.file.storageStatistics (Application Storage Statistics)](reference/apis/js-apis-file-storage-statistics.md) - [@ohos.file.volumeManager (Volume Management)](reference/apis/js-apis-file-volumemanager.md) - [@ohos.filemanagement.userFileManager (User Data Management)](reference/apis/js-apis-userFileManager.md) - [@ohos.fileshare (File Sharing)](reference/apis/js-apis-fileShare.md) + - AI + - [@ohos.ai.mindSporeLite (Inference)](reference/apis/js-apis-mindSporeLite.md) - Telephony Service - [@ohos.contact (Contacts)](reference/apis/js-apis-contact.md) - [@ohos.telephony.call (Call)](reference/apis/js-apis-call.md) @@ -922,6 +992,7 @@ - [@ohos.net.mdns (mDNS Management)](reference/apis/js-apis-net-mdns.md) - [@ohos.net.sharing (Network Sharing)](reference/apis/js-apis-net-sharing.md) - [@ohos.net.socket (Socket Connection)](reference/apis/js-apis-socket.md) + - [@ohos.net.statistics (Traffic Management)](reference/apis/js-apis-net-statistics.md) - [@ohos.net.webSocket (WebSocket Connection)](reference/apis/js-apis-webSocket.md) - [@ohos.request (Upload and Download)](reference/apis/js-apis-request.md) - Connectivity @@ -932,6 +1003,7 @@ - [@ohos.nfc.controller (Standard NFC)](reference/apis/js-apis-nfcController.md) - [@ohos.nfc.tag (Standard NFC Tags)](reference/apis/js-apis-nfcTag.md) - [@ohos.rpc (RPC)](reference/apis/js-apis-rpc.md) + - [@ohos.secureElement (SE Management)](reference/apis/js-apis-secureElement.md) - [@ohos.wifiManager (WLAN) (Recommended)](reference/apis/js-apis-wifiManager.md) - [@ohos.wifiManagerExt (WLAN Extension) (Recommended)](reference/apis/js-apis-wifiManagerExt.md) - [@ohos.wifi (WLAN) (To Be Deprecated Soon)](reference/apis/js-apis-wifi.md) @@ -945,6 +1017,7 @@ - [@ohos.accessibility.GesturePath (Gesture Path)](reference/apis/js-apis-accessibility-GesturePath.md) - [@ohos.accessibility.GesturePoint (Gesture Point)](reference/apis/js-apis-accessibility-GesturePoint.md) - [@ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)](reference/apis/js-apis-application-accessibilityExtensionAbility.md) + - [@ohos.base (Public Callback Information)](reference/apis/js-apis-base.md) - [@ohos.faultLogger (FaultLogger)](reference/apis/js-apis-faultLogger.md) - [@ohos.hichecker (HiChecker)](reference/apis/js-apis-hichecker.md) - [@ohos.hidebug (HiDebug)](reference/apis/js-apis-hidebug.md) @@ -964,6 +1037,7 @@ - [@ohos.systemDateTime (System Time and Time Zone)](reference/apis/js-apis-system-date-time.md) - [@ohos.systemTimer (System Timer)](reference/apis/js-apis-system-timer.md) - [@ohos.wallpaper (Wallpaper)](reference/apis/js-apis-wallpaper.md) + - [@ohos.WallpaperExtensionAbility (WallpaperExtensionAbility)](reference/apis/js-apis-WallpaperExtensionAbility.md) - [@ohos.web.webview (Webview)](reference/apis/js-apis-webview.md) - [Console](reference/apis/js-apis-logs.md) - [Timer](reference/apis/js-apis-timer.md) @@ -971,6 +1045,7 @@ - application - [AccessibilityExtensionContext](reference/apis/js-apis-inner-application-accessibilityExtensionContext.md) - Device Management + - [@ohos.app.ability.DriverExtensionAbility (DriverExtensionAbility)](reference/apis/js-apis-app-ability-driverExtensionAbility.md) - [@ohos.batteryInfo (Battery Information)](reference/apis/js-apis-battery-info.md) - [@ohos.batteryStatistics (Battery Statistics)](reference/apis/js-apis-batteryStatistics.md) - [@ohos.brightness (Screen Brightness)](reference/apis/js-apis-brightness.md) @@ -979,7 +1054,9 @@ - [@ohos.deviceAttest (Device Attestation)](reference/apis/js-apis-deviceAttest.md) - [@ohos.deviceInfo (Device Information)](reference/apis/js-apis-device-info.md) - [@ohos.distributedHardware.deviceManager (Device Management)](reference/apis/js-apis-device-manager.md) + - [@ohos.driver.deviceManager (Peripheral Management)](reference/apis/js-apis-driver-deviceManager.md) - [@ohos.geoLocationManager (Geolocation Manager)](reference/apis/js-apis-geoLocationManager.md) + - [@ohos.multimodalInput.gestureEvent (Gesture Input Event)](reference/apis/js-apis-multimodalinput-gestureevent.md) - [@ohos.multimodalInput.inputConsumer (Input Consumer)](reference/apis/js-apis-inputconsumer.md) - [@ohos.multimodalInput.inputDevice (Input Device)](reference/apis/js-apis-inputdevice.md) - [@ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)](reference/apis/js-apis-cooperate.md) @@ -1004,13 +1081,17 @@ - [@ohos.update (Update)](reference/apis/js-apis-update.md) - [@ohos.usbManager (USB Manager)](reference/apis/js-apis-usbManager.md) - [@ohos.vibrator (Vibrator)](reference/apis/js-apis-vibrator.md) + - application + - [DriverExtensionContext](reference/apis/js-apis-inner-application-driverExtensionContext.md) - Account Management - [@ohos.account.appAccount (App Account Management)](reference/apis/js-apis-appAccount.md) + - [@ohos.account.appAccount.AuthorizationExtensionAbility (App AuthorizationExtensionAbility)](reference/apis/js-apis-appAccount-authorizationExtensionAbility.md) - [@ohos.account.distributedAccount (Distributed Account Management)](reference/apis/js-apis-distributed-account.md) - [@ohos.account.osAccount (OS Account Management)](reference/apis/js-apis-osAccount.md) - Customization - [@ohos.configPolicy (Configuration Policy)](reference/apis/js-apis-configPolicy.md) - Enterprise Device Management + - [Enterprise Device Management Overview (for System Applications Only)](reference/apis/enterpriseDeviceManagement-overview.md) - [@ohos.enterprise.accountManager (Account Management)](reference/apis/js-apis-enterprise-accountManager.md) - [@ohos.enterprise.adminManager (Enterprise Device Management)](reference/apis/js-apis-enterprise-adminManager.md) - [@ohos.enterprise.applicationManager (Application Management)](reference/apis/js-apis-enterprise-applicationManager.md) @@ -1018,8 +1099,10 @@ - [@ohos.enterprise.dateTimeManager (System Time Management)](reference/apis/js-apis-enterprise-dateTimeManager.md) - [@ohos.enterprise.deviceControl (Device Control Management)](reference/apis/js-apis-enterprise-deviceControl.md) - [@ohos.enterprise.deviceInfo (Device Information Management)](reference/apis/js-apis-enterprise-deviceInfo.md) + - [@ohos.enterprise.deviceSettings (Device Settings Management)](reference/apis/js-apis-enterprise-deviceSettings.md) - [@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)](reference/apis/js-apis-EnterpriseAdminExtensionAbility.md) - [@ohos.enterprise.networkManager (Network Management)](reference/apis/js-apis-enterprise-networkManager.md) + - [@ohos.enterprise.restrictions (Restrictions)](reference/apis/js-apis-enterprise-restrictions.md) - [@ohos.enterprise.wifiManager (Wi-Fi Management)](reference/apis/js-apis-enterprise-wifiManager.md) - Common Library - [@ohos.buffer (Buffer)](reference/apis/js-apis-buffer.md) @@ -1145,7 +1228,9 @@ - [Polymorphic Style](reference/arkui-ts/ts-universal-attributes-polymorphic-style.md) - [restoreId](reference/arkui-ts/ts-universal-attributes-restoreId.md) - [Foreground Color](reference/arkui-ts/ts-universal-attributes-foreground-color.md) + - [Foreground Blur](reference/arkui-ts/ts-universal-attributes-foreground-blur-style.md) - [Click Effect](reference/arkui-ts/ts-universal-attributes-click-effect.md) + - [Accessibility](reference/arkui-ts/ts-universal-attributes-accessibility.md) - Touch Interactions - [Touch Target](reference/arkui-ts/ts-universal-attributes-touch-target.md) - [Hit Test Control](reference/arkui-ts/ts-universal-attributes-hit-test-behavior.md) @@ -1154,6 +1239,8 @@ - [Sheet Transition](reference/arkui-ts/ts-universal-attributes-sheet-transition.md) - [Obscuring](reference/arkui-ts/ts-universal-attributes-obscured.md) - [Universal Text Attributes](reference/arkui-ts/ts-universal-attributes-text-style.md) + - [Drag and Drop Control](reference/arkui-ts/ts-universal-attributes-drag-drop.md) + - [Safe Area](reference/arkui-ts/ts-universal-attributes-expand-safe-area.md) - Gesture Handling - [Gesture Binding Methods](reference/arkui-ts/ts-gesture-settings.md) - Basic Gestures @@ -1193,6 +1280,7 @@ - [Radio](reference/arkui-ts/ts-basic-components-radio.md) - [Rating](reference/arkui-ts/ts-basic-components-rating.md) - [RemoteWindow](reference/arkui-ts/ts-basic-components-remotewindow.md) + - [RichEditor](reference/arkui-ts/ts-basic-components-richeditor.md) - [RichText](reference/arkui-ts/ts-basic-components-richtext.md) - [ScrollBar](reference/arkui-ts/ts-basic-components-scrollbar.md) - [Search](reference/arkui-ts/ts-basic-components-search.md) @@ -1219,6 +1307,7 @@ - [Counter](reference/arkui-ts/ts-container-counter.md) - [Flex](reference/arkui-ts/ts-container-flex.md) - [FlowItem](reference/arkui-ts/ts-container-flowitem.md) + - [FormLink](reference/arkui-ts/ts-container-formlink.md) - [GridCol](reference/arkui-ts/ts-container-gridcol.md) - [GridRow](reference/arkui-ts/ts-container-gridrow.md) - [Grid](reference/arkui-ts/ts-container-grid.md) @@ -1261,6 +1350,8 @@ - [OffscreenCanvas](reference/arkui-ts/ts-components-offscreencanvas.md) - [OffscreenCanvasRenderingContext2D](reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md) - [Path2D](reference/arkui-ts/ts-components-canvas-path2d.md) + - Advanced Components + - [@ohos.multimedia.avCastPicker (AVCastPicker)](reference/arkui-ts/ohos-multimedia-avcastpicker.md) - Animation - [AnimatorProperty](reference/arkui-ts/ts-animatorproperty.md) - [Explicit Animation](reference/arkui-ts/ts-explicit-animation.md) @@ -1268,7 +1359,7 @@ - [Page Transition](reference/arkui-ts/ts-page-transition-animation.md) - [Component Transition](reference/arkui-ts/ts-transition-animation-component.md) - [Transition of Shared Elements](reference/arkui-ts/ts-transition-animation-shared-elements.md) - - [Motion Path Animation](reference/arkui-ts/ts-motion-path-animation.md) + - [Implicit Shared Element Transition](reference/arkui-ts/ts-transition-animation-geometrytransition.md) - Global UI Methods - Pop-up Window - [Alert Dialog Box](reference/arkui-ts/ts-methods-alert-dialog-box.md) @@ -1519,10 +1610,12 @@ - [Ethernet Connection Error Codes](reference/errorcodes/errorcode-net-ethernet.md) - [Network Sharing Error Codes](reference/errorcodes/errorcode-net-sharing.md) - [mDNS Error Codes](reference/errorcodes/errorcode-net-mdns.md) + - [Traffic Management Error Codes](reference/errorcodes/errorcode-net-statistics.md) - Connectivity - [Bluetooth Error Codes](reference/errorcodes/errorcode-bluetoothManager.md) - [Wi-Fi Error Codes](reference/errorcodes/errorcode-wifi.md) - [NFC Error Codes](reference/errorcodes/errorcode-nfc.md) + - [SE Error Codes](reference/errorcodes/errorcode-se.md) - [RPC Error Codes](reference/errorcodes/errorcode-rpc.md) - Basic Features - [Accessibility Error Codes](reference/errorcodes/errorcode-accessibility.md) @@ -1560,25 +1653,38 @@ - Test - [UiTest Error Codes](reference/errorcodes/errorcode-uitest.md) - Native APIs + - [Native API Introduction](reference/native-api-intro.md) - Modules - [Native XComponent](reference/native-apis/_o_h___native_x_component.md) - [HiLog](reference/native-apis/_hi_log.md) - [NativeWindow](reference/native-apis/_native_window.md) + - [OH_NativeBuffer](reference/native-apis/_o_h___native_buffer.md) - [Drawing](reference/native-apis/_drawing.md) + - [OH_NativeImage](reference/native-apis/_o_h___native_image.md) + - [NativeVsync](reference/native-apis/_native_vsync.md) - [Image](reference/native-apis/image.md) - [Rawfile](reference/native-apis/rawfile.md) + - [RDB](reference/native-apis/_r_d_b.md) - [MindSpore](reference/native-apis/_mind_spore.md) - [NeuralNeworkRuntime](reference/native-apis/_neural_nework_runtime.md) + - [AVCapability](reference/native-apis/_a_v_capability.md) + - [AVMuxer](reference/native-apis/_a_v_muxer.md) - [AudioDecoder](reference/native-apis/_audio_decoder.md) - [AudioEncoder](reference/native-apis/_audio_encoder.md) - [CodecBase](reference/native-apis/_codec_base.md) - [Core](reference/native-apis/_core.md) - [VideoDecoder](reference/native-apis/_video_decoder.md) - [VideoEncoder](reference/native-apis/_video_encoder.md) + - [AVDemuxer](reference/native-apis/_a_v_demuxer.md) + - [AVSource](reference/native-apis/_a_v_source.md) + - [OHAudio](reference/native-apis/_o_h_audio.md) - [HuksKeyApi](reference/native-apis/_huks_key_api.md) - [HuksParamSetApi](reference/native-apis/_huks_param_set_api.md) - [HuksTypeApi](reference/native-apis/_huks_type_api.md) - [Init](reference/native-apis/init.md) + - [Memory](reference/native-apis/memory.md) + - [Hitrace](reference/native-apis/_hitrace.md) + - [Vulkan](reference/native-apis/_vulkan.md) - Header Files - [drawing_bitmap.h](reference/native-apis/drawing__bitmap_8h.md) - [drawing_brush.h](reference/native-apis/drawing__brush_8h.md) @@ -1593,7 +1699,10 @@ - [external_window.h](reference/native-apis/external__window_8h.md) - [image_pixel_map_napi.h](reference/native-apis/image__pixel__map__napi_8h.md) - [log.h](reference/native-apis/log_8h.md) + - [native_buffer.h](reference/native-apis/native__buffer_8h.md) + - [native_image.h](reference/native-apis/native__image_8h.md) - [native_interface_xcomponent.h](reference/native-apis/native__interface__xcomponent_8h.md) + - [native_vsync.h](reference/native-apis/native__vsync_8h.md) - [raw_dir.h](reference/native-apis/raw__dir_8h.md) - [raw_file_manager.h](reference/native-apis/raw__file__manager_8h.md) - [raw_file.h](reference/native-apis/raw__file_8h.md) @@ -1606,20 +1715,39 @@ - [types.h](reference/native-apis/types_8h.md) - [neural_network_runtime_type.h](reference/native-apis/neural__network__runtime__type_8h.md) - [neural_network_runtime.h](reference/native-apis/neural__network__runtime_8h.md) + - [avcodec_audio_channel_layout.h](reference/native-apis/avcodec__audio__channel__layout_8h.md) + - [native_avcapability.h](reference/native-apis/native__avcapability_8h.md) - [native_avcodec_audiodecoder.h](reference/native-apis/native__avcodec__audiodecoder_8h.md) - [native_avcodec_audioencoder.h](reference/native-apis/native__avcodec__audioencoder_8h.md) - [native_avcodec_base.h](reference/native-apis/native__avcodec__base_8h.md) - [native_avcodec_videodecoder.h](reference/native-apis/native__avcodec__videodecoder_8h.md) - [native_avcodec_videoencoder.h](reference/native-apis/native__avcodec__videoencoder_8h.md) + - [native_avdemuxer.h](reference/native-apis/native__avdemuxer_8h.md) - [native_averrors.h](reference/native-apis/native__averrors_8h.md) - [native_avformat.h](reference/native-apis/native__avformat_8h.md) - [native_avmemory.h](reference/native-apis/native__avmemory_8h.md) + - [native_avmuxer.h](reference/native-apis/native__avmuxer_8h.md) + - [native_avsource.h](reference/native-apis/native__avsource_8h.md) + - [native_audiocapturer.h](reference/native-apis/native__audiocapturer_8h.md) + - [native_audiorenderer.h](reference/native-apis/native__audiorenderer_8h.md) + - [native_audiostream_base.h](reference/native-apis/native__audiostream__base_8h.md) + - [native_audiostreambuilder.h](reference/native-apis/native__audiostreambuilder_8h.md) - [native_huks_api.h](reference/native-apis/native__huks__api_8h.md) - [native_huks_param.h](reference/native-apis/native__huks__param_8h.md) - [native_huks_type.h](reference/native-apis/native__huks__type_8h.md) + - [oh_cursor.h](reference/native-apis/oh__cursor_8h.md) + - [oh_predicates.h](reference/native-apis/oh__predicates_8h.md) + - [oh_value_object.h](reference/native-apis/oh__value__object_8h.md) + - [oh_values_bucket.h](reference/native-apis/oh__values__bucket_8h.md) + - [relational_store_error_code.h](reference/native-apis/relational__store__error__code_8h.md) + - [relational_store.h](reference/native-apis/relational__store_8h.md) - [syscap_ndk.h](reference/native-apis/syscap__ndk_8h.md) + - [purgeable_memory.h](reference/native-apis/purgeable__memory_8h.md) + - [trace.h](reference/native-apis/trace_8h.md) + - [vulkan_ohos.h](reference/native-apis/vulkan__ohos_8h.md) - Structs - [OH_Drawing_BitmapFormat](reference/native-apis/_o_h___drawing___bitmap_format.md) + - [OH_NativeBuffer_Config](reference/native-apis/_o_h___native_buffer___config.md) - [OH_NativeXComponent_Callback](reference/native-apis/_o_h___native_x_component___callback.md) - [OH_NativeXComponent_MouseEvent](reference/native-apis/_o_h___native_x_component___mouse_event.md) - [OH_NativeXComponent_MouseEvent_Callback](reference/native-apis/_o_h___native_x_component___mouse_event___callback.md) @@ -1641,6 +1769,9 @@ - [OH_NN_UInt32Array](reference/native-apis/_o_h___n_n___u_int32_array.md) - [OH_AVCodecAsyncCallback](reference/native-apis/_o_h___a_v_codec_async_callback.md) - [OH_AVCodecBufferAttr](reference/native-apis/_o_h___a_v_codec_buffer_attr.md) + - [OH_AVRange](reference/native-apis/_o_h___a_v_range.md) + - [OH_AudioCapturer_Callbacks_Struct](reference/native-apis/_o_h___audio_capturer___callbacks___struct.md) + - [OH_AudioRenderer_Callbacks_Struct](reference/native-apis/_o_h___audio_renderer___callbacks___struct.md) - [OH_Huks_Blob](reference/native-apis/_o_h___huks___blob.md) - [OH_Huks_CertChain](reference/native-apis/_o_h___huks___cert_chain.md) - [OH_Huks_KeyInfo](reference/native-apis/_o_h___huks___key_info.md) @@ -1653,19 +1784,39 @@ - [OH_Huks_ParamSet](reference/native-apis/_o_h___huks___param_set.md) - [OH_Huks_PubKeyInfo](reference/native-apis/_o_h___huks___pub_key_info.md) - [OH_Huks_Result](reference/native-apis/_o_h___huks___result.md) + - [OH_Cursor](reference/native-apis/_o_h___cursor.md) + - [OH_Predicates](reference/native-apis/_o_h___predicates.md) + - [OH_Rdb_Config](reference/native-apis/_o_h___rdb___config.md) + - [OH_Rdb_Store](reference/native-apis/_o_h___rdb___store.md) + - [OH_VBucket](reference/native-apis/_o_h___v_bucket.md) + - [OH_VObject](reference/native-apis/_o_h___v_object.md) + - [VkExternalFormatOHOS](reference/native-apis/_vk_external_format_o_h_o_s.md) + - [VkImportNativeBufferInfoOHOS](reference/native-apis/_vk_import_native_buffer_info_o_h_o_s.md) + - [VkMemoryGetNativeBufferInfoOHOS](reference/native-apis/_vk_memory_get_native_buffer_info_o_h_o_s.md) + - [VkNativeBufferFormatPropertiesOHOS](reference/native-apis/_vk_native_buffer_format_properties_o_h_o_s.md) + - [VkNativeBufferPropertiesOHOS](reference/native-apis/_vk_native_buffer_properties_o_h_o_s.md) + - [VkNativeBufferUsageOHOS](reference/native-apis/_vk_native_buffer_usage_o_h_o_s.md) + - [VkSurfaceCreateInfoOHOS](reference/native-apis/_vk_surface_create_info_o_h_o_s.md) - Standard Libraries - - [libc Standard Libraries](reference/native-lib/third_party_libc/musl.md) + - [libc](reference/native-lib/third_party_libc/musl.md) + - [c++](reference/native-lib/third_party_libc/cpp.md) - [Node-API](reference/native-lib/third_party_napi/napi.md) - [libuv](reference/native-lib/third_party_libuv/libuv.md) - [OpenSL ES](reference/native-lib/third_party_opensles/opensles.md) + - [OpenGL ES](reference/native-lib/third_party_opengl/opengles.md) + - [EGL](reference/native-lib/third_party_opengl/egl.md) + - [Zlib](reference/native-lib/third_party_zlib/zlib.md) + - [Vulkan](reference/native-lib/third_party_vulkan/vulkan.md) - Appendix - [libc Symbols Not Exported](reference/native-lib/third_party_libc/musl-peculiar-symbol.md) - - [libc Symbols That May Fail to Be Invoked Due to Permission Control](reference/native-lib/third_party_libc/musl-permission-control-symbol.md) - - [EGL Symbols Exported from Native APIs](reference/native-lib/third_party_opengl/egl-symbol.md) - - [OpenGL ES 3.0 Symbols Exported from Native APIs](reference/native-lib/third_party_opengl/openglesv3-symbol.md) + - [libc Symbols That May Fail to Call Due to Permission Control](reference/native-lib/third_party_libc/musl-permission-control-symbol.md) + - [EGL Symbols Exported](reference/native-lib/third_party_opengl/egl-symbol.md) + - [OpenGL ES 3.0 Symbols Exported](reference/native-lib/third_party_opengl/openglesv3-symbol.md) + - [Vulkan Symbols Exported](reference/native-lib/third_party_vulkan/vulkan-symbol.md) - FAQs - [Full SDK Compilation Guide](faqs/full-sdk-compile-guide.md) - [Guide to Switching to Full SDK](faqs/full-sdk-switch-guide.md) + - [Using Native APIs (NDK) of the OpenHarmony SDK in a CMake Project](faqs/howto-migrate-cmake-with-ohosndk.md) - [Application Model Development](faqs/faqs-ability.md) - ArkUI Framework Development (ArkTS) - [ArkTS Syntax Usage](faqs/faqs-arkui-arkts.md)